ASL
Loading...
Searching...
No Matches
Queue< T > Class Template Reference

Detailed Description

template<class T>
class asl::Queue< T >

A simple queue of items.

There are two operations: put() adds an element at the end of the queue, and get() gets the first element and removes it. Method length() returns the current number of items.

queue.put(1);
queue.put(2);
int x1 = queue.get(); // gets 1
int x2 = queue.get(); // gets 2
An Array is a contiguous and resizable array of any type of elements.
Definition Array.h:69
Array()
Creates an empty array.
Definition Array.h:86

You can also use operators << and >>:

queue << 1 << 2;
int x1, x2;
if(queue.length() >= 2)
queue >> x1 >> x2;
int length() const
Returns the number of elements in the array.
Definition Array.h:171

#include <Queue.h>

Inherits Array< T >.

Public Member Functions

void put (const T &x)
 Appends an item at the end.
 
T get ()
 Gets and removes the item at the start.
 
- Public Member Functions inherited from Array< T >
 Array ()
 Creates an empty array.
 
 Array (int n)
 Creates an array of n elements.
 
 Array (const T *p, int n)
 Creates an array of n elements and copies them from the pointer p.
 
 Array (int n, const T &x)
 Creates an array of n elements and gives them the value x.
 
template<class K >
Array< Kwith () const
 Returns a copy of this array with all element converted to another type.
 
int length () const
 Returns the number of elements in the array.
 
Arrayreserve (int m)
 Reserves space for m elements without increasing actual length (to make appending faster)
 
Arrayresize (int m)
 Resizes the array to m elements; up to m existing elements are preserved.
 
void clear ()
 Removes all elements in the array.
 
 operator const T * () const
 Returns a pointer to the base of the array.
 
 operator T* ()
 Returns a pointer to the base of the array.
 
const Tptr () const
 Returns a pointer to the first element.
 
Tptr ()
 Returns a pointer to the first element.
 
Tdata ()
 Returns a pointer to the first element.
 
const Tdata () const
 Returns a pointer to the first element.
 
bool operator== (const Array &b) const
 Tests for equality of all elements of both arrays.
 
const Toperator[] (int i) const
 Returns the element at index i.
 
Toperator[] (int i)
 Returns the element at index i.
 
const Tlast () const
 Returns a reference to the last element.
 
Tlast ()
 Returns a reference to the last element.
 
int indexOf (const T &x, int j=0) const
 Returns the index of the first element with value x; The search starts at position j; The value -1 is returned if no such element is found.
 
bool contains (const T &x) const
 Returns true if the array contains an element equal to x.
 
Arraydup ()
 Makes this array independent of others.
 
Array clone () const
 Returns an independent copy of this array.
 
void copy (const Array &b)
 Copies another array's contents into this array.
 
void copy (const T *p, int n)
 Copies n elements pointed to by p (the array is resized to n)
 
Arrayoperator= (const Array &b)
 Assigns array b into this array by reference.
 
Arrayoperator<< (const T &x)
 Adds element x at the end of the array.
 
Arrayoperator, (const T &x)
 The same as <<, useful to create pseudo-array-literals.
 
Arrayremove (int i, int n=1)
 Removes n elements (1 be default) starting at position i.
 
bool removeOne (const T &x, int i0=0)
 Removes the first element with value x starting at index i0; Returns true if an element was found and removed.
 
Arrayinsert (int k, const T &x)
 Inserts x at position k.
 
Array reversed () const
 Returns the elements of the array in reversed order.
 
Array slice (int i1, int i2=0) const
 Returns a section of the array, from element i1 up to but not including element i2; If i2 is omitted the subarray will take elements up te the last.
 
Arrayappend (const Array &b)
 Adds all elements from array b at the end of the array.
 
Arrayappend (const T *p, int n)
 Adds n elements from array pointed by p at the end of this array.
 
Array concat (const Array &b) const
 Returns the concatenation of this array and b.
 
Array operator| (const Array &b) const
 Returns the concatenation of this array and b.
 
Arraysort ()
 Sorts the array using the elements' < operator "in place".
 
template<class Less >
Arraysort (Less f)
 Sorts the array using the elements' < operator "in place".
 
template<class F >
ArraysortBy (F f, bool ascending=true)
 Sorts the array by the elements' f comparable property (in ascending order by default)
 
String join (const String &sep) const
 Returns a string representation of the array, formed by joining its elements with the given separator string sep; The elements need to be convertible to String.
 
template<class F >
Array map (F f) const
 Returns an array formed by applying a function to each item.
 
template<class K , class F >
Array< Kmap_ (F f) const
 Returns an array of another type formed by applying a function to each item.
 
template<class F >
Array filter (F f) const
 Returns an array containing the items in this array satisfying a condition.
 
template<class F >
ArrayremoveIf (F f)
 Removes items that meet a predicate.
 
ArrayremoveLast ()
 Removes the last item in the array.
 

The documentation for this class was generated from the following file: