Interview Questions

194. Implement a circular queue using an array. Implement enque and deque.

Microsoft Interview Questions and Answers


(Continued from previous question...)

194. Implement a circular queue using an array. Implement enque and deque.

Question:
Implement a circular queue using an array. Implement enque and deque.


maybe an answer:


#define SUCCESS 0
#define FULL -1
#define EMPTY -2
#define SIZE 20
class Q
{
public:
Q()
{
front = tail = 0;
}
int push(int d)
{
if((tail+1) %SIZE == front )
return FULL;
data[tail++] = d;
tail %= SIZE;
return SUCCESS;
}
int pop(int &d)
{
if(tail == front)
return EMPTY;
d = data[front++];

return SUCCESS;
}
private:
int data[SIZE];
int front, tail;
}q;

(Continued on next question...)

Other Interview Questions