0

hello iam trying a circular queue in linked list and array there are two questions for me
1.how can circular queue can be implemented in a normal linked list??i think it can be implemented in circular singly linked list right??

2.if i implement it in array how i will connect last element with first element????

2
Contributors
4
Replies
7
Views
5 Years
Discussion Span
Last Post by WaltP
0

1.how can circular queue can be implemented in a normal linked list??i think it can be implemented in circular singly linked list right??

Right

2.if i implement it in array how i will connect last element with first element????

When you reach the last element of the array, return to the first element

0

r u saying like dis???@waltp

int n=5;
int front=-1,int rear=-1;
void enqueue()
{
if(rear==n-1)
{
front=0;
}
else
{
rear=rear+1;
queue[rear]=value;



}

Edited by WaltP: 250 posts and still using leet speek? You know better!

0

Format your code!!! You know better!

It's a circular queue. front and rear would be independent of each other. You've tied them together messing up the contents of the queue. But the idea is correct.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.