queue class : Sort(bool) method

Description

Gets a new queue that sorted the caller queue.

Syntax

queueInstance.Sort(bool order)

Arguments

ClassNameDescription
boolorderSort order.

Return value

ClassDescription
some queueA new queue that is sorted.

Sample code

queue{int} orgQueue = new queue{int}();

orgQueue.Enqueue(10);

orgQueue.Enqueue(8);

orgQueue.Enqueue(9);

queue{int} ascQueue = orgQueue.Sort(true);

ascQueue.Dequeue(); // 8

ascQueue.Dequeue(); // 9

ascQueue.Dequeue(); // 10

queue{int} descQueue = orgQueue.Sort(false);

descQueue.Dequeue(); // 10

descQueue.Dequeue(); // 9

descQueue.Dequeue(); // 8

Notes

This method is added in Ver 1.1.0.0.

If the argument is true, the returned queue is sorted in ascending order. That is, when you dequeue an element from returned queue, the element is taken out in ascending order.

If the argument is false, the returned queue is sorted in descending order. That is, when you dequeue an element from returned queue, the element is taken out in descending order.

Returns a new queue that is sorted. The order of the caller queue does not change.

The returned queue is a shallow copy of the caller queue. That is, the caller and the returned queue refer to the same element.

It will throw an exception (RtypeException) if you call this method on queues other than queue{int}, queue{long}, queue{real}, queue{bool}, or queue{string}.

Links for reference

None

Copyright © Rice All rights reserved.