Ad Code

Ticker

6/recent/ticker-posts

Queue in Data Structure in Hindi | Queue data structure in hindi-oklesson

data structure using c in hindi की इस series में आज हम पढेंगे Queue in data structure in hindi. मुझे आशा है आपको यह पोस्ट जरुर पसंद आएगी | 
Queue एक non-primitive data structure है जिसका मतलब होता है पंक्ति | इसमे data एक end से insert होता है तथा दूसरे end से delete होता है| यह FIFO(First in First Out) तकनीक को follow करता है|alert-success
इसकी पिछली पोस्ट में हमने देखा था कि stack क्या है, और stack पर कौन कौन से operation perform किये जाते है| इसे आप जरुर पढ़े , stack को पढ़कर आप Queue को बहुत ही जल्दी समझ जायेंगे| 

Topics we cover in Queue data structure 

  • Queue क्या है ? 
  • Types of Queue 
  • implementation of a Queue 
  • Operation perform on a Queue 
  • insertion or enqueue in simple Queue 
  • dequeue or Deletion in a Queue 
  • Traverse a Queue 
  • full code of a simple Queue 

Queue क्या है(what is Queue) ? 

Queue एक non-primitive data structure है जिसका मतलब होता है पंक्ति | इसमे data एक end से insert होता है तथा दूसरे end से delete होता है| यह FIFO(First in First Out) तकनीक को follow करता है जबकि stack डाटा structure FILO(First in Last Out) तकनीक को follow करता है| FIFO का मतलब यह है की पहले जो आया है, उसका काम पहले होगा | 

Queue in data structure in hindi

 Queue का उपयोग आप real - लाइफ example से बहुत अच्छी तरह से समझ पायेंगे| उदाहरण के लिए यदि आप किसी bus के द्वारा कही जाना चाहते है, तो उसके लिए आपको पहले ticket लेनी होती है, और ticket को लेने के लिए आपको एक लाइन में लगना पड़ता है| अब लाइन में सबसे आगे जो होगा , उसे ticket पहले मिलती है, और वही व्यक्ति ही सबसे पहले bus में बैठेगा | इसी तरह से एक के बाद एक लोग ticket लेते है, और bus में चढ़ते है| इसे ही पंक्ति(Queue) कहते है| इसके और भी बहुत सारे real-life examples है , जिनकी मदद से आप इसे और अच्छी तरह से समझ सकते है| चलिए अब हम देखते है की Queue कितने प्रकार की होती है| 
Application: CPU task Scheduling , Disk Scheduling, Buffering , etc.alert-info

Queue के प्रकार(Types of Queue) 

 Queue मुख्यतः चार प्रकार की होती है | जिनका problem को solve करने के हिसाब से use किया जाता है| 
  • Simple Queue 
  • Circular Queue 
  • Double-ended Queue 
  • Priority Queue
इस पोस्ट में हम सारे प्रोग्राम simple Queue के माध्यम से सीखेंगे | 

Implementation of a Queue 

एक simple Queue को implement करने के लिए काफी सारे तरीके है| आप इसे Array की मदद से भी implement कर सकते है| आप इसे Dynamic Array की मदद से भी implement कर सकते है| आप इसे linked list की मदद से भी implement कर सकते है| 
//Implement Queue Using Structure & Array
struct Queue {
int ArraySize;
int front;
int rear;
int *myArray;
};
Queue को implement करने के लिए हमने Dynamic Array का use किया है| एक Structure है ,जिसमे तीन int type के variable और एक int type का pointer variable declare किया गया है| पहला variable Array का size बताता है| दूसरा व तीसरा variable Queue के first और last index को दिखायेंगे | और चौथे variable की मदद से हम एक dynamic ऐरे create बनायेंगे | 

 Operation on a Queue 

 stack की तरह ही हम Queue पर तीन प्रकार के operation perform करते है| function के काम करने का तरीका एकदम same है, बस थोडा सा logic implementation को सही करना है | 
  • enqueue or insertion in a Queue 
  • dequeue or Deletion in a Queue 
  • Traverse a Queue 
इन सारे operation को हम code के माध्यम से one-by-one देखेंगे | जिससे आपको theory के साथ साथ प्रोग्राम भी समझ में आ जाए| 
Also Read:

insertion in a Queue in data structure 

 इंसर्शन का मतलब होता किसी वैल्यू को Queue के अंदर insert करना | लेकिन हमें किसी वैल्यू को Queue में insert करने के लिए निम्न बाते या Algorithm ध्यान रखनी चाहिए| 
सबसे पहले यह check करे कि कही Queue खाली(empty) तो नहीं है| 
यदि हाँ, तो यूजर को एक message देकर प्रोग्राम को end करे| 
यदि नहीं, तो वैल्यू को Queue में insert कर दे 
 इतना करने के बाद आपका प्रोग्राम end हो जाएगा | 
इन्ही बातो को ध्यान में रखकर हम एक function लिखेंगे , जिससे User को कोई दिक्कत न हो प्रोग्राम को समझने में| 
void QueueInsertion(struct Queue *Start,int data) {
if(isFull(Start)){
printf("Queue is Overflow\n");
exit(0);
}
else
Start->rear++;
Start->myArray[Start->rear]=data;
}
इस प्रोग्राम को ध्यान से देखे तो आप इसे बड़े ही आराम से समझ पायेंगे , यदि आप stack को जानते है| इसमें हमने के condition दी है, जो यह check करेगा की कही Queue full तो नहीं है| अगर ऐसा है तो user को एक message show होगा “Queue is Overflow” | यदि नहीं, तो हम else की body में आ जायेंगे और स्टेप्स को perform करेंगे | इसमें हमने Queue को check करने के लिए एक function का use किया है आप चाहे तो इसे direct if की body में भी implement कर सकते है| program आसानी से समझ में आये इसके लिए हमने code को function के रूप में लिखा है | 

deletion in a Queue in data structure 

एक simple Queue में किसी एलिमेंट को डिलीट करना या हटाना बहुत ही simple है| क्योकि हमें पता है , की डाटा को remove करने के लिए एक दूसरा end मिलता है| जिससे इसका code बहुत ही simple हो जाता है| Queue में एलिमेंट को डिलीट करने के लिए निम्न बाते ध्यान में रखे | 
सबसे पहले यह check करे, कि कही Queue खाली तो नहीं है| क्योकि यदि Queue खाली होगी तो कोई element डिलीट ही नहीं होगा| 
यदि हाँ, तो यूजर को एक message मिल जाए “Queue is Underflow” और प्रोग्राम end हो जाए | 
यदि नहीं तो else की body में आ जायेंगे, और instruction के अनुसार एलिमेंट delete हो जाएगा | 
इतना करने के बाद delete function successful execute हो जाएगा| और वैल्यू डिलीट हो जायेगी | 
void QueueDelete(struct Queue* Start){
int a;
if(isEmpty(Start)){
printf("Queue is Underflow\n");
}
else
Start->front++;
a=Start->myArray[Start->front];
printf("\n %d remove from Queue",a);
printf("\n");
}
यदि आप code को ध्यान से देखे, तो हमने if की condition में एक function को call किया है जो यह check करता है, की कही Queue खाली तो नहीं है| यदि Queue खाली है , तो यूजर को एक message मिल जाए| else की body में front की वैल्यू में increment हो गया है, जिसकी वजह से Array में से एक एलिमेंट डिलीट हो गया है |
Also Read:

Traverse in a Queue in data structure 

Queue में traverse function को implement करना logically रूप से थोडा सा मुश्किल है| क्योकि इसमें यह पता नहीं चल पाता की loop को स्टार्ट कहाँ से करे, और कहाँ पर loop को terminate करे | 
void QueueDisplay(struct Queue* disp){
int i;
for(i=disp->rear;i>disp->front;i--){
printf("%d ",disp->myArray[disp->rear]);
disp->rear--;
}}
यदि आप Traverse function को देखे, तो Queue को display करने के लिए QueueDisplay नाम का एक function बनाया है, जिसमे for loop को Queue के rear variable से स्टार्ट किया है, और यह loop तब तक चलेगा, जब तक rear की वैल्यू front से छोटी नहीं हो जाती| इस प्रकार हम किसी Queue के सारे एलिमेंट को display कर सकते है| 

अब बात करते है , main() function की body जिसके अंदर हमने Array को dynamically create किया है| और कुछ function को बनाया है, जिसकी बात हम पहले ही कर चुके है| हमने Array का size 4 रखा है, आप इसे बढाकर कितना भी कर सकते है, प्रोग्राम में कोई change नहीं होगा| एक बार element को Queue में insert करने के बाद हमने QueueDisplay function को call किया है, और एक बार वैल्यू के डिलीट हो जाने के बाद फिर से Queuedisplay function को call किया है, जिससे यह पता चल सके की value डिलीट हुई है या नहीं | आप इन function को अपने according भी call कर सकते है| 

full code of a simple Queue 

अभी हमने उपर देखा कि किस तरह से हम अलग अलग operation को perfom करने के लिए अलग अलग function को create करते है| तो चलिए अब हम देखते है, कि जब सारे function को हम प्रोग्राम में add कर देंगे तो प्रोग्राम किस प्रकार बनकर ready होगा | 
#include<stdio.h>
#include<stdlib.h>
//Implement Queue Using Structure
struct Queue {
int ArraySize;
int front;
int rear;
int *myArray;
};
//Check Queue is Empty or not
int isEmpty(struct Queue* check){
if(check->rear==check->front)
return 1;
else
return 0;
}
//Check Queue is full or not
int isFull(struct Queue* check) {
if(check->rear==check->ArraySize-1)
return 1;
else
return 0;
}
//funtion of enqueue(insert) element in a queue
void QueueInsertion(struct Queue *Start,int data) {
if(isFull(Start)){
printf("Queue is Overflow\n");
exit(0);
}
else
Start->rear++;
Start->myArray[Start->rear]=data;
}
//funtion of dequeue(delete) element in a queue
void QueueDelete(struct Queue* Start){
int a;
if(isEmpty(Start)){
printf("Queue is Underflow\n");
}
else
Start->front++;
a=Start->myArray[Start->front];
printf("\n %d remove from Queue",a);
printf("\n");
}
int main() {
struct Queue QueueReady;
QueueReady.ArraySize=4;
QueueReady.front=-1;
QueueReady.rear=-1;
QueueReady.myArray=(int *)malloc(QueueReady.ArraySize * sizeof(int));
//call functions to insert element in a Queue
QueueInsertion(&QueueReady,20);
QueueInsertion(&QueueReady,30);
QueueInsertion(&QueueReady,40);
QueueInsertion(&QueueReady,50);
//call function to display Queue 
QueueDisplay(QueueReady);
//Call function to delete element in a Queue
QueueDelete(&QueueReady);
//After Deletion, again display Queue
QueueDisplay(QueueReady);
return 0;
}
//define QueueDisplay function to print Queue
void QueueDisplay(struct Queue* disp){
int i;
for(i=disp->rear;i>disp->front;i--){
printf("%d ",disp->myArray[disp->rear]);
disp->rear--;
}}


हमें उम्मीद है, की आपको Queue in data structure in hindi जरुर समझ में आया होगा | यदि आपका कोई सवाल या सुझाव हो तो comment करके पूछ सकते है| Please Share with your friends
Tags:
queue data structure applications,
queue data structure in c,
queue data structure works on the principle of,
queue data structure definition,
queue data structure array,
a queue data structure is used for,
queue data structure code,
queue data structure c program,
queue data structure c code,

Post a Comment

0 Comments