Operations on Circular Queue | Data Structures Tutorial

preview_player
Показать описание
Operations on Circular Queue | Data Structures Tutorial

💡 Also Watch

Subscribe to our channel and hit the bell 🔔🔔🔔 icon to get video updates.

💡 Visit Our Websites

#DataStructures #Training #Course #Tutorials
--------------------------

💡 About NareshIT:

"Naresh IT is having 14+ years of experience in software training industry and the best Software Training Institute for online training, classroom training, weekend training, corporate training of Hadoop, Salesforce, AWS, DevOps, Spark, Data Science, Python, Tableau, RPA , Java, C#.NET, ASP.NET, Oracle, Testing Tools, Silver light, Linq, SQL Server, Selenium, Android, iPhone, C Language, C++, PHP and Digital Marketing in USA, Hyderabad, Chennai and Vijayawada, Bangalore India which provides online training across all the locations

--------------------------

💡 Our Online Training Features:
🎈 Training with Real-Time Experts
🎈 Industry Specific Scenario’s
🎈 Flexible Timings
🎈 Soft Copy of Material
🎈 Share Videos of each and every session.

--------------------------

💡 Please write back to us at

Рекомендации по теме
Комментарии
Автор

Algorithm for display/traverse:
1. If rear and front are equal to -1 then the queue is empty.
2. Else if "rear" is greater than or equal to "front", print from front to rear.
3. Else print from 0 to "rear" and then "front" to "size - 1".



Code for display/traverse :


void traverse()
{
if(front == -1 && rear == -1)
{
printf("\nQueue is empty.\n\n");
}
else if(rear >= front)
{
printf("\nElements in the queue:");
for(int i = front;i<=rear;i++)
{
printf("\n%d", queue[i]);
}
printf("\n\n");
}
else
{
printf("\nElements in the queue:");
for(int j = 0;j<=rear;j++)
{
printf("\n%d", queue[j]);
}
for(int k = front;k<=size-1;k++)
{
printf("\n%d", queue[k]);
}
printf("\n\n");
}

}




Just make adjustments according to variables and preferred formatting, I hope this helps ;)

VarunSharma-ttdc
Автор

Use if((front==rear+1) || ((SIZE==rear+1)&&(front==0))) otherwise else if (rear = SIZE-1) cannot be entered. Please take care.

tirumalakanakagiri
Автор

In case, we want insert an element and front is 2 and rear is (size -1) then it will print queue is full. I think condition should be if((front == rear + 1) || ((rear = size -1) && front == 0)).

ayushgangwar
Автор

sir, i have watched all your lectures ..that help me much in understanding basic concepts of DS
sir ..please upload all the rest lectures of DS... like TREE, GRAPH etc

hanumatlalvishwakarma
Автор

I think the first condition of insert function should be like
if((rear == size-1 && front == 0) || front == rear +1 )

dharmendrakotarya
Автор

Sir, you're literally amazing. Such crisp and clear explaination, you must probably the best asset of that naresh it company. thank you so much. One small advice; please execute this whole program and show it for the viewers, it add even more value to this video.

anilsunny
Автор

Good going in clearing the concepts. In insert function for queue full the condition to be checked is if((front ==rear) || ((SIZE==rear+1) && (front == 0))) otherwise elseif (rear = SIZE-1) cannot be entered. Please take care.

tirumalakanakagiri
Автор

first if condition is wrong sir
Correct one :-
front==0))
{
cout<<"Cqueue is full";
}

Ujjwalkumar-iyxe
Автор

Sir but there is a problem in display only ..what if queue is not full..please give the code about display

dhruvishah
Автор

Excellent teaching sir, even our sir didn't explained like this super teaching

shivaratan.m
Автор

I found one mistake in this program.
insertion of queue
logic when queue is full
sir, your logic is
when size==rear+1 or front==rear +1 it will print queue is full. But.
There is one case in which size == rear + 1 but queue is not full i.e nothing but front =2 and rear = size -1 observe in this case queue is not full but acc. to your logic queue is full and it will print queue is full.
so,
its correct logic is as follows.
if ( (rear+1==size && front ==0) or (front == 0) )
Thank You Sir we really enjoyed your videos thanks for your contribution for online video it really help us.

meandev
Автор

Sir thank you so much sir for clear explanation

apparao
Автор

HERE IS THE COMPLETE CODE:
#include<stdio.h>
#include<stdlib.h>
#define CAPACITY 5
int cqueue [CAPACITY];
int rear=0;
int front=0;

void insert(int);
void delete();
void display();

void insert(int ele)
{

{
printf("cqueue is full");
}

else if(front==-1 && rear==-1)
{
front =0;
rear=0;
cqueue[rear]=ele;
}

else if(rear==CAPACITY-1)
{
rear=0;
cqueue[rear]=ele;
}

else
{
rear++;
cqueue[rear]=ele;
}
}

void delete()
{
int ele;
if(front==-1 && rear==-1)
printf("cqueue is empty");

else if(front==rear)
{
ele=cqueue[front];
front=-1;
rear=-1;
}

else if(front==CAPACITY-1)
{
ele=cqueue[front];
front=0;
}

else
{
ele=cqueue[front];
front++;
}
printf("deleted element is %d\n", ele);
}

void display()
{
if(front==-1 && rear==-1)
printf("cqueue is empty");
else
{
front=1;
printf("cqueue elemets are: ");
while(front<=rear)
{
printf("%d ", cqueue[front]);
front++;
}

printf("\n");
}

}


void main()
{
int ch, ele;
while(1)
{
printf("Available choices of circular queue are\n");
printf("1.Insert\n");
printf("2.Delete\n");
printf("3.Display\n");
printf("4.Exit\n");

printf("Enter your choice: ");
scanf("%d", &ch);
switch(ch)
{
case 1: printf("enter element to be insert\n");
scanf("%d", &ele);
insert(ele);
break;
case 2: delete();
break;
case 3: display();
break;
case 4: exit(0);
default: printf("invalid input\n");
}
printf("\n");
}
}

goyaldeekshant
Автор

*thank you so much sir i understand this concept clearly*

indiantechandengineering
Автор

Sir i have doubt about rear == size - 1. While performing insert.
Second else if never execute rear == size - 1.

gulabpatel
Автор

Sir please make a video on double ended queue "Deoueue".

pankajsingh-ifvs
Автор

For cqueue full condition use if((rear==SIZE-1 && front==0) || (rear==front-1))
& for others_
else if(front==-1 && rear==-1)
else if(rear==SIZE-1 && front!=0)
& for last statement use "else"

akshatkumar
Автор

suppose if we write whole queue means now R==4 and F==0, in short whole que is full. but now if i delete one element i.e F becomes ==1 and now if i wants to insert one element, practically 0th location is free but according to ur insertion program it will still print"QUEUE IS FULL" and it will never enter to second last else_if part.

RohitChavan™
Автор

your leacture is very good sir . I never expect like this somuch tq sir please upload more videos sir

Naidu_
Автор

sir in your insertion function if (rear=size-1) condition occurs it will always print queue is full and will never set rear =0 because if comes first

piyushkumar-kuxz