class deque #( type T = int ) extends collection#( T )
Implements a double-ended queue using a queue.
| T | optional The type of data collected in a deque. The default is int. |
| deque | Implements a double-ended queue using a queue. |
| Functions | |
| new | Creates a new deque. |
| add | virtual Adds the given element at the end of this deque. |
| add_first | virtual Adds the given element at the front of this deque. |
| add_last | virtual Adds the given element at the end of this deque. |
| clear | virtual Removes all of the elements from this deque. |
| clone | virtual Returns a shallow copy of this deque. |
| contains | virtual Returns 1 if this deque contains the specified element. |
| get | virtual Retrieves the head of the deque and remove the element. |
| get_first | virtual Retrieves the head of the deque and remove the element. |
| get_last | virtual Retrieves the tail of the deque and remove the element. |
| get_iterator | virtual Returns an iterator over the elements in this deque. |
| get_descending_iterator | virtual Returns an iterator over the elements in this deque in reverse order. |
| peek | virtual Retrieves the head of the deque but does not remove the element. |
| peek_first | virtual Retrieves the head of the deque but does not remove the element. |
| peek_last | virtual Retrieves the tail of the deque but does not remove the element. |
| pop | virtual Pops an element from the deque as if it is a stack. |
| push | virtual Pushes an element to the deque as if it is a stack. |
| remove | virtual Removes the specified element from this deque. |
| remove_first | virtual Removes the first element from this deque. |
| remove_last | virtual Removes the last element from this deque. |
| remove_first_occurrence | virtual Removes the first occurrence of the specified element by traversing the deque from head to tail. |
| remove_last_occurrence | virtual Removes the last occurrence of the specified element by traversing the deque from tail to head. |
| size | virtual Returns the number of elements in this deque. |
function new( collection#(T) c = null, comparator#(T) cmp = null, formatter#(T) fmtr = null )
Creates a new deque.
| c | optional A collection whose elements are to be added to this deque. |
| cmp | optional A strategy object used to compare the elements of type T. If not specified or null, comparator #(T) is used. The default is null. |
| fmtr | optional A strategy object that provides a function to convert the element of type T to a string. If not specified or null, hex_formatter #(T) is used. The default is null. |
deque#(int) int_dq = new();
virtual function bit contains( T e )
virtual Returns 1 if this deque contains the specified element.
| e | An element to be checked. |
If this deque contains e, returns 1. Otherwise, returns 0.
deque#(int) int_dq = new(); void'( int_dq.add( 123 ) ); assert( int_dq.contains( 123 ) == 1 ); assert( int_dq.contains( 456 ) == 0 );
virtual function bit get( ref T e )
virtual Retrieves the head of the deque and remove the element. This function is equivalent to get_first.
| e | The head of the deque to be returned. |
If e is valid, returns 1. Otherwise, returns 0.
deque#(int) int_dq = new(); int i; void'( int_dq.add( 123 ) ); assert( int_dq.get( i ) == 1 ); assert( i == 123 );
virtual function bit get_first( ref T e )
virtual Retrieves the head of the deque and remove the element.
| e | The head of the deque to be returned. |
If e is valid, returns 1. Otherwise, returns 0.
deque#(int) int_dq = new(); int i; void'( int_dq.add( 123 ) ); assert( int_dq.get_first( i ) == 1 ); assert( i == 123 );
virtual function bit get_last( ref T e )
virtual Retrieves the tail of the deque and remove the element.
| e | The tail of the deque to be returned. |
If e is valid, returns 1. Otherwise, returns 0.
deque#(int) int_dq = new(); int i; void'( int_dq.add( 123 ) ); assert( int_dq.get_last( i ) == 1 ); assert( i == 123 );
virtual function iterator#( T ) get_iterator()
virtual Returns an iterator over the elements in this deque.
An iterator.
deque#(int) int_dq = new();
iterator#(int) it;
string s;
void'( int_dq.add( 123 ) );
void'( int_dq.add( 456 ) );
it = int_dq.get_iterator();
while ( it.has_next() ) s = { s, $sformatf( "%0d ", it.next() ) };
assert( s == "123 456 " );
virtual function iterator#( T ) get_descending_iterator()
virtual Returns an iterator over the elements in this deque in reverse order.
A descending iterator.
deque#(int) int_dq = new();
iterator#(int) it;
string s;
void'( int_dq.add( 123 ) );
void'( int_dq.add( 456 ) );
it = int_dq.get_descending_iterator();
while ( it.has_next() ) s = { s, $sformatf( "%0d ", it.next() ) };
assert( s == "456 123 " );
virtual function bit peek( ref T e )
virtual Retrieves the head of the deque but does not remove the element. This function is equivalent to peek_first.
| e | The head of the deque to be returned. |
If e is valid, returns 1. Otherwise, returns 0.
deque#(int) int_dq = new(); int i; void'( int_dq.add( 123 ) ); void'( int_dq.add( 456 ) ); assert( int_dq.peek( i ) == 1 ); assert( i == 123 );
virtual function bit peek_first( ref T e )
virtual Retrieves the head of the deque but does not remove the element.
| e | The head of the deque to be returned. |
If e is valid, returns 1. Otherwise, returns 0.
deque#(int) int_dq = new(); int i; void'( int_dq.add( 123 ) ); void'( int_dq.add( 456 ) ); assert( int_dq.peek_first( i ) == 1 ); assert( i == 123 );
virtual function bit peek_last( ref T e )
virtual Retrieves the tail of the deque but does not remove the element.
| e | The tail of the deque to be returned. |
If e is valid, returns 1. Otherwise, returns 0.
deque#(int) int_dq = new(); int i; void'( int_dq.add( 123 ) ); void'( int_dq.add( 456 ) ); assert( int_dq.peek_last( i ) == 1 ); assert( i == 456 );
virtual function T pop()
virtual Pops an element from the deque as if it is a stack.
The head of the deque. If the deque is empty, the value of type T read from a nonexistent queue entry is returned (See IEEE Std 1800-2012 Table 7-1).
deque#(int) int_dq = new(); int_dq.push( 123 ); int_dq.push( 456 ); assert( int_dq.pop() == 456 );
virtual function bit remove( T e )
virtual Removes the specified element from this deque. This function is equivalent to remove_first_occurrence.
| e | An element to be removed. |
If this deque changed as a result of the call, 1 is returned. Otherwise, 0 is returned.
deque#(int) int_dq = new(); void'( int_dq.add( 123 ) ); void'( int_dq.add( 456 ) ); assert( int_dq.remove( 123 ) == 1 ); assert( int_dq.remove( 789 ) == 0 );
<remove_first_occurence>
virtual function bit remove_first()
virtual Removes the first element from this deque.
If this deque is not empty, 1 is returned. Otherwise, 0 is returned.
deque#(int) int_dq = new(); void'( int_dq.add( 123 ) ); assert( int_dq.remove_first() == 1 ); assert( int_dq.remove_first() == 0 ); // deque is empty
virtual function bit remove_last()
virtual Removes the last element from this deque.
If this deque is not empty, 1 is returned. Otherwise, 0 is returned.
deque#(int) int_dq = new(); void'( int_dq.add( 123 ) ); assert( int_dq.remove_last() == 1 ); assert( int_dq.remove_last() == 0 ); // deque is empty
virtual function bit remove_first_occurrence( T e )
virtual Removes the first occurrence of the specified element by traversing the deque from head to tail.
| e | An element to be removed. |
If this deque changed as a result of the call, 1 is returned. Otherwise, 0 is returned.
deque#(int) int_dq = new(); void'( int_dq.add( 123 ) ); void'( int_dq.add( 456 ) ); assert( int_dq.remove_first_occurrence( 123 ) == 1 ); assert( int_dq.remove_first_occurrence( 789 ) == 0 );
virtual function bit remove_last_occurrence( T e )
virtual Removes the last occurrence of the specified element by traversing the deque from tail to head.
| e | An element to be removed. |
If this deque changed as a result of the call, 1 is returned. Otherwise, 0 is returned.
deque#(int) int_dq = new(); void'( int_dq.add( 123 ) ); void'( int_dq.add( 456 ) ); assert( int_dq.remove_last_occurrence( 123 ) == 1 ); assert( int_dq.remove_last_occurrence( 789 ) == 0 );
Implements a double-ended queue using a queue.
class deque #( type T = int ) extends collection#( T )
Creates a new deque.
function new( collection#(T) c = null, comparator#(T) cmp = null, formatter#(T) fmtr = null )
virtual Adds the given element at the end of this deque.
virtual function bit add( T e )
virtual Adds the given element at the front of this deque.
virtual function void add_first( T e )
virtual Adds the given element at the end of this deque.
virtual function void add_last( T e )
virtual Removes all of the elements from this deque.
virtual function void clear()
virtual Returns a shallow copy of this deque.
virtual function collection#( T ) clone()
virtual Returns 1 if this deque contains the specified element.
virtual function bit contains( T e )
virtual Retrieves the head of the deque and remove the element.
virtual function bit get( ref T e )
virtual Retrieves the head of the deque and remove the element.
virtual function bit get_first( ref T e )
virtual Retrieves the tail of the deque and remove the element.
virtual function bit get_last( ref T e )
virtual Returns an iterator over the elements in this deque.
virtual function iterator#( T ) get_iterator()
virtual Returns an iterator over the elements in this deque in reverse order.
virtual function iterator#( T ) get_descending_iterator()
virtual Retrieves the head of the deque but does not remove the element.
virtual function bit peek( ref T e )
virtual Retrieves the head of the deque but does not remove the element.
virtual function bit peek_first( ref T e )
virtual Retrieves the tail of the deque but does not remove the element.
virtual function bit peek_last( ref T e )
virtual Pops an element from the deque as if it is a stack.
virtual function T pop()
virtual Pushes an element to the deque as if it is a stack.
virtual function void push( T e )
virtual Removes the specified element from this deque.
virtual function bit remove( T e )
virtual Removes the first element from this deque.
virtual function bit remove_first()
virtual Removes the last element from this deque.
virtual function bit remove_last()
virtual Removes the first occurrence of the specified element by traversing the deque from head to tail.
virtual function bit remove_first_occurrence( T e )
virtual Removes the last occurrence of the specified element by traversing the deque from tail to head.
virtual function bit remove_last_occurrence( T e )
virtual Returns the number of elements in this deque.
virtual function int size()
singleton Provides strategies to compare objects.
class comparator#( type T = int )
singleton Provides a strategy to convert an object of type T to a string using a hexadecimal format.
class hex_formatter #( type T = int ) extends formatter#( T )