142k views
3 votes
What is queue operations in datastructures?

1 Answer

6 votes

Answer:

Queue- It is a data structure,unlike stacks we can insert and delete elements from both sides.

It works on the principle FiFo(first in first out) i.e the element which is inserted at the starting will be the one for deleting.

We can perform many operations on queue like enqueue(),dequeue() and many more.

Queue Operations

enqueue()-This operation is used to add elements in Queue,we add element to rear.

Example-

Queue.prototype.enqueue = insertval(5)

{

this.array.push(5); //inserting elements to a queue

}

dequeue()-This operation is used to remove elements from Queue,while removing data from front.

Example-

Queue. prototype. dequeue = removalval(5)

{

this.array.pop(5); //removing elements from a queue

}

peek()-This operation is used to get the element from front i.e first element.

Example-

int peek()

{

return queue[front];

}

isfull()-This operation is used to check whether the queue is full or not.

Example-

bool isfull()

{

if(rear == MAXSIZE - 1) //checking queue is full

return true;

else

return false;

}

isempty()-This operation is used to check whether the queue is empty or not.

Example

bool isempty()

front > rear) //checking queue is empty or not

return true;

else

return false;

User Nima Yousefi
by
5.3k points