stack class : Sort(bool) method

Description

Gets a new stack that sorted the caller stack.

Syntax

stackInstance.Sort(bool order)

Arguments

ClassNameDescription
boolorderSort order.

Return value

ClassDescription
some stackA new stack that is sorted.

Sample code

stack{int} orgStack = new stack{int}();

orgStack.Push(10);

orgStack.Push(8);

orgStack.Push(9);

stack{int} ascStack = orgStack.Sort(true);

ascStack.Pop(); // 8

ascStack.Pop(); // 9

ascStack.Pop(); // 10

stack{int} descStack = orgStack.Sort(false);

descStack.Pop(); // 10

descStack.Pop(); // 9

descStack.Pop(); // 8

Notes

This method is added in Ver 1.1.0.0.

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

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

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

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

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

Links for reference

None

Copyright © Rice All rights reserved.