Queue / linear queue / static queue Data Structure, Insertion, Deletion and Traversing Operations , Applications of Queue

Linear queue:- queue is a linear data structure. It is collection of ordered data elements. It is also known as FIFO system or FCFS system. It means an element which is inserted first will be deleted first. Here data elements will be inserted from one end of queue called rear and deleted from the other end called front. We can use Array or Linked list representation to store queue in memory.Daily life examples of queue are Students line at fees counter, Passengers line at bus stand/railway station/airport,  Viewers line at movie ticket counter etc.
เคฒीเคจिเคฏเคฐ/ เคธ्เคŸेเคŸिเค• เค•्เคฏू เคเค• เคฒीเคจिเคฏเคฐ เคกाเคŸा เคธ्เคŸ्เคฐเค•्เคšเคฐ เคนै। เคฏเคน เค•्เคฐเคฎเคฌเคฆ्เคง เคกाเคŸा เคเคฒेเคฎेंเคŸ्เคธ เค•ा เคธंเค—्เคฐเคน เคนै। เค‡เคธे FIFO (เคซเคฐ्เคธ्เคŸ เค‡เคจ เคซเคฐ्เคธ्เคŸ เค†เค‰เคŸ) เคฏा FCFS (เคซเคฐ्เคธ्เคŸ เค•เคฎ เคซเคฐ्เคธ्เคŸ เคธเคฐ्เคต) เคธिเคธ्เคŸเคฎ เค•े เคจाเคฎ เคธे เคญी เคœाเคจा เคœाเคคा เคนै เค…เคฐ्เคฅाเคค เค•्เคฏू เคฎें เคฏเคฆि เค•िเคธी เคเคฒिเคฎेंเคŸ เค•ो เคธเคฌเคธे เคชเคนเคฒे เค‡เคจ्เคธเคฐ्เคŸ เค•िเคฏा เคœाเคคा เคนै, เคคเคฌ เค‰เคธे เคนी เคธเคฌเคธे เคชเคนเคฒे เคกिเคฒीเคŸ เค•िเคฏा เคœाเคคा เคนै। เคฏเคนाँ เคเคฒिเคฎेंเคŸ เค•ा เค‡ंเคธเคฐ्เคถเคจ เค•्เคฏू เค•े เคฐिเคฏเคฐ เค›ोเคฐ เคชเคฐ เคคเคฅा เคกिเคฒीเคถเคจ เคซ्เคฐंเคŸ เค›ोเคฐ เคธे เค•िเคฏा เคœाเคคा เคนै। เคนเคฎ เค…เคฐे เคเคตं เคฒिंเค•्เคก เคฒिเคธ्เคŸ เคฎें เคธे เค•िเคธी เคเค• เค•ा เคช्เคฐเคฏोเค— เค•เคฐ เคฎेเคฎोเคฐी เคฎें เค•्เคฏू เคคैเคฏाเคฐ เค•เคฐ เคธเค•เคคे เคนै। เคฆैเคจिเค• เคœीเคตเคจ เคฎें เค•्เคฏू เค•े เค‰เคฆाเคนเคฐเคฃ เคนै -  เคซीเคธ เค•ाเค‰ंเคŸเคฐ เค•े เคฌाเคนเคฐ เค›ाเคค्เคฐों เค•ी เคชंเค•्เคคि , เคฌเคธ เคธ्เคŸैंเคก / เคฐेเคฒเคตे เคธ्เคŸेเคถเคจ/ เคเคฏเคฐเคชोเคฐ्เคŸ เคฎें เคชैเคธेंเคœเคฐ เค•ी เคฒाเค‡เคจ, เคฎूเคตी เคŸिเค•ेเคŸ เค•ाเค‰ंเคŸเคฐ เค•े เคฌाเคนเคฐ เคต्เคฏूเค…เคฐเคธ เค•ी เค•เคคाเคฐ เค‡เคค्เคฏाเคฆि।
Queue is mainly of five types-
เค•्เคฏू เคฎुเค–्เคฏเคค: เคชांเคš เคช्เคฐเค•ाเคฐ เค•ा เคนोเคคा เคนै- 
1. Linear/static queue (เคฒीเคจिเคฏเคฐ/ เคธ्เคŸेเคŸिเค• เค•्เคฏू)
2. Physical queue (เคซिเคœिเค•เคฒ เค•्เคฏू)
3. Circular queue (เคธเคฐ्เค•ुเคฒเคฐ เค•्เคฏू)
4. Double ended queue (เคกเคฌเคฒ เคंเคกेเคก เค•्เคฏू)
5. Priority queue (เคช्เคฐाเคฏोเคฐिเคŸी เค•्เคฏू)

Operations performed on queue are as follows:-

1. Insertion:- To add new element in queue is called insertion operation. This work is done on rear of queue and rear is increased by 1. If first element is inserted in queue then set front=rear=0. If(rear=N-1) It means queue is full and insertion operation is performed, then overflow condition will occur.
เค•्เคฏू  เคฎें เค•िเคธी เคจเค เคเคฒिเคฎेंเคŸ เค•ो เคœोเฅœเคจा, เค‡ंเคธเคฐ्เคถเคจ เค‘เคชเคฐेเคถเคจ เค•เคนเคฒाเคคा เคนै। เคฏเคน เค•ाเคฐ्เคฏ เค•्เคฏू เค•े เคฐिเคฏเคฐ เคชเคฐ เค•िเคฏा เคœाเคคा เคนै เคเคตं เคฐिเคฏเคฐ เค•ो เคเค• เคธे เคฌเคขाเคฏा เคœाเคคा เคนै। เคฏเคฆि เค•्เคฏू เคฎें เคชเคนเคฒे เคเคฒिเคฎेंเคŸ เค•ा เค‡ंเคธเคฐ्เคถเคจ เค•िเคฏा เคœाเคคा เคนै เคคเคฌ front=rear=0 เคธेเคŸ เค•िเคฏा เคœाเคคा เคนै। เคฏเคฆि rear=N-1 เค…เคฐ्เคฅाเคค เค•्เคฏू เคซुเคฒ เคนो เคเคตं เค‡ंเคธเคฐ्เคถเคจ เค‘เคชเคฐेเคถเคจ เค•िเคฏा เคœाเคฏे , เคคเคฌ เค“เคตเคฐเคซ्เคฒो เค•ंเคกीเคถเคจ เค‰เคค्เคชเคจ्เคจ เคนोเคคी เคนै।    
Algorithm / Function for Insertion operation-

void insertion(){
if(rear==N-1){
printf("Overflow Condition\n");
getch();
return;
}
printf("Enter an Item to insert\n");
scanf("%d",&item);
if(rear==-1){
front=rear=0;
}
else{
rear++;
}
queue[rear]=item;
printf("insertion completed\n");
getch();
return;
}

2. Deletion:- To remove/ delete an element from queue is called deletion. This work is done on front of queue and front is increased by 1. If last element is remained in queue i.e.. front=rear then set front=rear= -1. When front=-1, It means queue is empty and we perform deletion operation then underflow condition will occur.
เค•्เคฏू เคธे เค•िเคธी เคเคฒिเคฎेंเคŸ เค•ो เคนเคŸाเคจा/ เคจिเค•ाเคฒเคจा , เคกिเคฒीเคถเคจ เค‘เคชเคฐेเคถเคจ เค•เคนเคฒाเคคा เคนै। เคฏเคน เค•ाเคฐ्เคฏ เค•्เคฏू เค•े เคซ्เคฐंเคŸ เคธे เค•िเคฏा เคœाเคคा เคนै เคเคตं เคซ्เคฐंเคŸ เค•ो เคเค• เคธे เคฌเคขाเคฏा เคœाเคคा เคนै। เคฏเคฆि เค•्เคฏू เคฎें เค…ंเคคिเคฎ เคเคฒिเคฎेंเคŸ(front=rear) เค•ा เคกिเคฒीเคถเคจ เค•िเคฏा เคœाเคคा เคนै เคคเคฌ front=rear=-1 เคธेเคŸ เค•िเคฏा เคœाเคคा เคนै। เคฏเคฆि front=-1 เค…เคฐ्เคฅाเคค เค•्เคฏू เค–ाเคฒी เคนो เคเคตं เคกिเคฒीเคถเคจ เค‘เคชเคฐेเคถเคจ เค•िเคฏा เคœाเคฏे , เคคเคฌ เค…ंเคกเคฐเคซ्เคฒो เค•ंเคกीเคถเคจ เค‰เคค्เคชเคจ्เคจ เคนोเคคी เคนै।    
Algorithm / Function for Deletion operation-

void deletion(){
if(front==-1){
printf("underflow Condition\n");
getch();
return;
}
item=queue[front];
if(front==rear){
front=rear=-1;
}
else
{
front++;
}
printf("Deletion completed\n");
printf("%d is deleted\n",item);
getch();
return;
}

3. Traversing:- To visit/ print of all elements of queue is called traversing. This work is done from front to rear of queue. If front= -1 or rear= -1, it means queue is empty and then Traversing operation cant be performed.
เค•्เคฏू เคฎें เค‰เคชเคธ्เคฅिเคค เคธเคญी เคเคฒिเคฎेंเคŸ เค•ो เคŸ्เคฐेเคตเคฐ्เคธ/ เคตिเคœिเคŸ/เคเค•्เคธेเคธ/เคช्เคฐिंเคŸ เค•เคฐเคจा, เคŸ्เคฐेเคตเคฐเคธींเค— เค‘เคชเคฐेเคถเคจ เค•เคนเคฒाเคคा เคนै। เคฏเคน เค•ाเคฐ्เคฏ front เคธे rear เคคเค• เค•िเคฏा เคœाเคคा เคนै। เคฏเคฆि  front=-1 เค…เคฐ्เคฅाเคค เค•्เคฏू เค–ाเคฒी เคนै, เคคเคฌ เคŸ्เคฐेเคตเคฐเคธींเค— เค‘เคชเคฐेเคถเคจ เคจเคนीं เค•िเคฏा เคœा เคธเค•เคคा เคนै।   
Algorithm/ Function for Traversing Operation:-

void traversing(){
int i;
if(front==-1){
printf("Queue is Empty\n");
getch();
return;
}
printf("Linear Queue is:");
for(i=front;i<=rear;i++){
printf(" %d ",queue[i]);
}
printf("front=%d and rear=%d\n",front,rear);
printf("Traversing completed");
getch();
return;
}

Example:-


Comments

Post a Comment

Popular posts from this blog

Priority Queue

Data Structure and Algorithms (DSA) USING C/C++ Topics Covered