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:
Anonymous2009-01-20 22:09
>> if SortedQueue.Top = SortedQueue.Free and SortedQueue.Queue_State = Filled then
null;
else
Enqueue(Smallest, SortedQueue);
end if;
lol
Name:
Anonymous2009-01-20 22:26
This is actually pretty decent. Why are you using Ada?
Name:
Anonymous2009-01-20 22:37
>>3
To learn concurrency. That's why I'm learning Ada anyway. I have mostly just been using it to do stuff I would normally do in other languages so far.
Name:
Anonymous2009-01-21 0:48
SELECTION SORT
Name:
Anonymous2009-01-21 0:53
This is my quickSort in, yeah, you know.
qSort [] = []
qSort (x:xs) = qSort l ++ [x] ++ qSort h
where (l,h) = partition (<x) xs