Constructor
new CircularQueue(max)
Example
var cq = new CircularQueue (3);
Parameters:
| Name | Type | Description |
|---|---|---|
max |
Number | the length of queue |
Methods
(static) back()
This method is used to get the last value in this circular queue, but does not remove.
Example
var cq = new CircularQueue (3);
cq.push(1);
cq.push(2);
var ret = cq.back() // ret1 = 2
Returns:
This method returns the last value of this circular queue, or null if this circular queue is empty.
(static) clear()
This method is used to nullify this circular queue and make all variables initial.
Example
var cq = new CircularQueue (3);
cq.push(1);
cq.push(2);
cq.push(3);
cq.clear();
(static) front()
This method is used to get the first value in this circular queue, but does not remove.
Example
var cq = new CircularQueue (3);
cq.push(1);
cq.push(2);
var ret = cq.front() // ret1 = 1
Returns:
This method returns the first value of this circular queue, or null if this circular queue is empty.
(static) isEmpty() → {Boolean}
This method is used to check if this circular queue is empty.
Example
var cq = new CircularQueue (3);
var ret1 = cq.isEmpty(); // ret1 = true
cq.push(1);
var ret2 = cq.isEmpty(); // ret2 = false
Returns:
This method returns ‘true’ if this circular queue is empty or ‘false’ if this circular queue is not empty.
- Type
- Boolean
(static) isFull() → {Boolean}
This method is used to check if this circular queue is full.
Example
var cq = new CircularQueue (3);
var ret1 = cq.isFull(); // ret1 = false
cq.push(1);
var ret2 = cq.isFull(); // ret2 = true
Returns:
This method returns ‘true’ if this circular queue is full or ‘false’ if this circular queue is not full.
- Type
- Boolean
(static) pop()
This method is used to remove value from this circular queue.
Example
var cq = new CircularQueue (3);
cq.push(1);
cq.push(2);
cq.pop() // 1 will be removed.
Returns:
This method returns the value which is poped.
(static) push(value)
This method is used to insert the specified value into this circular queue.
Example
var cq = new CircularQueue (3);
cq.push(1);
cq.push(2);
Parameters:
| Name | Type | Description |
|---|---|---|
value |
undefined | The value to be inserted to this circular queue. |
(static) size()
This method is used to get the number of values in this circular queue.
Example
var cq = new CircularQueue (3);
cq.push(1);
cq.push(2);
cq.push(3);
var size = cq.size(); // size = 3
Returns:
This method returns the number of values in this circular queue.
(static) toString()
This method shows state of this circular queue.
Example
var cq = new CircularQueue (3);
cq.push(1);
cq.push(2);
cq.push(3);
cq.toString(); // 1, 2, 3