CircularQueue

CircularQueue

배열로 이루어진 큐를 사용하다가 가장 마지막 부분을 쓰면 다시 제일 처음부터 큐를 채우기 시작하는 형태의 자료구조이다.

Constructor

new CircularQueue(max)

Author:
  • yicho93@gmail.com
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