Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

This is my queue selection sort in Ada.

Name: Anonymous 2009-01-20 22:08

   procedure QSort (KQueue: in out Queue_Type) is
      Smallest : Element;
      Candidate : Element;
      TempQueue : Queue_Type;
      EmptyQueue : Queue_Type;
      SortedQueue : Queue_Type;
   begin
      Dequeue(Smallest, KQueue);

      -- Create an empty queue.  A bit hacky
      Enqueue(Smallest, EmptyQueue);Dequeue(Candidate, EmptyQueue);

      loop

         -- We're done
         if KQueue.Queue_State = Empty and TempQueue.Queue_State = Empty then
            Enqueue(Smallest, SortedQueue);
            KQueue := SortedQueue;
            exit;
         end if;

         -- Check the current smallest element against the next item in the input queue
         if KQueue.Queue_State = Filled then
            Dequeue(Candidate, KQueue);
         end if;
         if Smallest < Candidate then
            Enqueue(Candidate, TempQueue);
         else
            Enqueue(Smallest, TempQueue);
            Smallest := Candidate;
         end if;

         -- We found the smallest element in the input queue for this iteration
         if KQueue.Queue_State = Empty then
            if SortedQueue.Top = SortedQueue.Free and SortedQueue.Queue_State = Filled then
               null;
            else
               Enqueue(Smallest, SortedQueue);
            end if;

            KQueue := TempQueue;
            TempQueue := EmptyQueue;
            Dequeue(Smallest, KQueue);
         end if;   

      end loop;

Name: Anonymous 2009-01-21 3:48

>>7
Because a queue and a list are totally different

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List