 Queues

Prev: What are Queues?

Queue Methods

The built-in methods associated with any queue provide an easy way of manipulating the queue as well as data inside the queue. There are seven methods associated with queue. These are described below.

size()

This method provides the current size of the queue. So, for instance, my_q.size() returns the size of my_q. As is obvious, the size is a non-negative integer.

insert()

This method inserts an element in a queue. For example, my_q.insert(i, e) inserts the element e in the location i of the queue my_q and is equivalent to:

my_q = {my_q[0:i-1], e, my-q[i, \$]}

delete()

The purpose of delete() is to, well, delete a specified item. my_q.delete(i) deletes the element at the position i and is equivalent to:

my_q = {my_q[0:i-1], my-q[i+1, \$]}

pop_front()

This method returns the first element (i.e., the 0th element) and then removes it from the queue. Thus, e = my_q.pop_front() is equivalent of:

e = my_q; my_q = my_q[1, \$];

pop_back()

As one can guess, this method returns the last element and then removes it from the queue. Thus, e = my_q.pop_back() is equivalent of:

e = my_q[\$]; my_q = my_q[0, \$-1];

push_front()

This method inserts an element at the front of a queue. Thus, my_q.push_front(e) is equivalent of:

my_q = {e, my_q};

push_back()

This method inserts an element at the end of a queue. my_q.push_back(e) is equivalent of:

my_q = {my_q, e};

Prev: What are Queues?    Join Verification Management Group

Shop Amazon - Contract Cell Phones & Service Plans Book of the Month    