User guide
24-166
SystemVerilog Testbench Constructs
sort()
The sort() method sorts the element in an ascending order using the
expression in the with construct. The with expression is optional here.
Syntax
task array_name.sort() [with (expression)];
Example 24-28
queue1.sort();
queue2.sort() with (item.i );
In the first example the queue1 is sorted in ascending order of the
value of the elements provided they are of a integral type. In the
second example queue2 is a queue of class objects and the class
contains an element i, here the objects are sorted in ascending order
depending on the value of the member variable i.
rsort()
The rsort() method sorts the elements in the array in a descending order
using the expression in the with construct. The with expression is
optional here.
Syntax
task array_name.rsort() [with (expression)];
Example 24-29
queue1.rsort();
queue2.sort() with (item.i * item.r);