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:-


1 comment:

Stack Data Structure, Push, Pop and Peek Operations , Applications of Stack

Stack is a linear data structure. It is collection of ordered data elements. It is also known as LIFO system (last in first out). It means i...