हिंदी माध्यम नोट्स
Categories: C Language in hindi
Queues : Implementation As Array in c language in hindi , queue ko arrey ki tarah implement kaise kare
queue ko arrey ki tarah implement kaise kare , Queues : Implementation As Array in c language in hindi :-
Stack और Queues एक linear struture जो की एक particular order को फॉलो करता है |इस order को FIFO कहते है |Queues का एक्सम्प्ले है किसी ticket के लिए लगी line |इस line मे जो लोग पहले आते है उसे ticket पहले मिलती है |stack और Queues मे केवल एक difference होता है की stack मे recently add element डिलीट होता है लेकिन Queues मे जो element पहले आता है वो डिलीट होता है |
Queues के operation
1.EnQueues
इस operation मे Queues मे data को add किया जाता है |अगर Queues full होते है तब overfull condition आ जाती है |
2.DeQueues
इस operation मे ,Queues से data को डिलीट किया जाता है |जिस order मे data enter होता है उसी order मे data डिलीट होता है |
3. Front
इस operation मे , Queues के front position पर स्थित element को return किया जाता है |
4.Rear
4.Rear
इस operation मे , Queues के rear position पर स्थित element को return किया जाता है |
Queues के Application
Queues का इस्तेमाल उस condition मे किया जाता है जहा पर प्रोसेस को immediately नहीं करना होता है |सबसे famous application होता है breadth first serach |Queues का property के कारन ,Queues को कई condition मे use कर सकते है |
1.जब किसी एक resource ( keyboard ,printer ,mouse ) आदि को बहुत operation मे shared होताहै |जैसे डिस्क scheduling ,disk scheduling |
2.जब किसी data को asynchronously transfer होता है |इसका मतलब है जब data को input फॉर्म मे त्रंफेर करना complusly नहीं होती है |जैसे buffers , pipes , file IO आदि
Queues का array implementation
Souce Code
#include <stdio.h>
#define size 50
int array[size];
int rear = – 1;
int front = – 1;
main()
{
char ch;
while (1)
{
printf(“‘I’.Insert element to queue \n”);
printf(” ‘D’.Delete element from queue \n”);
printf(” “V’.View all elements of queue \n”);
printf(” ‘Q’.Quit \n”);
printf(“Enter your ch : “);
scanf(“%c”, &ch);
switch (ch)
{
case I:
insertinqueue();
break;
case D:
deleteinqueue();
break;
case V
viewqueue();
break;
case Q:
exit(1);
default:
printf(“Wrong ch \n”);
}
}
}
insertinqueue()
{
int new_item;
if (rear == size – 1)
printf(“Queue Overflow \n”);
else
{
if (front == – 1)
front = 0;
printf(“Enter new element : “);
scanf(“%d”, &new_item);
rear = rear + 1;
array[rear] = new_item;
}
}
deleteinqueue()
{
if (front == – 1 || front > rear)
{
printf(“Queue Underflow \n”);
return ;
}
else
{
printf(” Delete element : %d\n”, array[front]);
front = front + 1;
}
}
display()
{
int i;
if (front == – 1)
printf(” Empty Queues \n”);
else
{
printf(“Queue is : \n”);
for (i = front; i <= rear; i++)
printf(“%d “, array[i]);
printf(“\n”);
}
}
Explantion
इस प्रोग्राम चार function है :-
1.main() : इस function मे यूजर द्वारा perform function के लिए choice को input करते है |इसके लिए
I for insert के लिए
D for डिलीट के लिए
V for view के लिए
E for exit operation के लिए
इसके अलावा तीन यूजर define function को declare किया जाता है :-
1.deleteinqueue() : इस function का use ,queue मे से data को डिलीट करने के लिए किया जाता है |
2.viewqueue() : इस function का use ,queue के सभी element को display करने के लिए किया जाता है |
3.insertinqueue() : इस function का use ,queue मे data को insert करने के लिए किया जाता है |
insertinqueue() मे ,
1.सबसे पहले एक नए variable को declare किया गया है जो की new element को hold करता है जिसे insert करना है |
2.फिर condition को check किया जाता है |
3.अगर rear की value , size-1 बके सामान होती है तब
3.i-overfull की condition आ जाती है |
3.ii- अब rear की rear+1 से set हो जाता है |और array की rear position पर new_data की value assign हो जाती है |
deleteinqueue()
1.सबसे पहले condition को check की जाती है |
2.अगर front की value ‘-1’ से check होती है और front की value को rear से check होती है |दोनों compression मे and operation होता है |
3.अगर front की value ‘-1’ है या front की value, rear की value से बड़ी होती है तब
3.i-underflow की condition आ जाती है |
3.ii- डिलीट element print होता है और front ,front-1 से रिसेट हो जाता है |
display()
1.सबसे पहले condition को check किया जाता है |
2.front ‘-1’ है तब
2.i-queue empty का message हो जाता है |
2.ii-अन्यथा ,queue के element को display किया जाता ही |queue के element को display करने का logic array के element को display की तरह है |
इसमें loop चलाया जाता है |और एक एक करके सभी element को print किया जाता है |
2.i-queue empty का message हो जाता है |
2.ii-अन्यथा ,queue के element को display किया जाता ही |queue के element को display करने का logic array के element को display की तरह है |
इसमें loop चलाया जाता है |और एक एक करके सभी element को print किया जाता है |
Recent Posts
मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi
malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…
4 weeks ago
कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए
राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…
4 weeks ago
हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained
hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…
1 month ago
तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second
Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…
1 month ago
चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi
chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…
1 month ago
भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi
first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…
1 month ago