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

सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है

सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…

23 hours ago

मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the

marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…

24 hours ago

राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi

sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…

3 days ago

गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi

gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…

3 days ago

Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन

वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…

3 months ago

polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten

get all types and chapters polity notes pdf in hindi for upsc , SSC ,…

3 months 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