JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

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
इस 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 किया जाता है |
Sbistudy

Recent Posts

Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic

Question Tag Definition • A question tag is a small question at the end of a…

2 weeks ago

Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)

Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…

2 weeks ago

Report Writing examples in english grammer How to Write Reports explain Exercise

Report Writing • How to Write Reports • Just as no definite rules can be laid down…

2 weeks ago

Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th

Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…

2 weeks ago

विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features

continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…

2 weeks ago

भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC

भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…

2 weeks ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now