हिंदी माध्यम नोट्स
Queue : Implementation With Linked List in c language in hindi , क्यु को लिंक लिस्ट के साथ use करना हिंदी में
struct employee
{
int salary;
struct employee *address;
};
इस उदहारण मे , employee का structure है जो linked list के एक node को define करता है |जिसमे salary ,linked list का item field है |address linked list का address field है |
यहा पर address एक structure है जो front ,rear और nodes की सख्या को रखता है |इसलिए Queue को तीन तरह से पढ़ा जा सकता है |(i) count (ii)front (iii) rear |
किसी Queue with linked लिस्ट मे तीन node होते है |count node ,front और rear node को लिंक करता है |अतः किसी Queue का structure होता है :-
struct Queue
{
int *front;
int *rear;
int count;
};
किसी linked लिस्ट को initial करना next काम होते है |अतः किसी Queue मे front = null ,rear=null और count =0 से initial करते है |जैसे
struct Queue
{
int *front=NULL;
int *rear=NULL;
int count=0;
};
जब Queue मे underflow और overfull किक condition को check किया जाता है |तब अगर rear की value null होती तब Queue empty होता है |अतः हम Queue के status को easily प्राप्त कर लेते है | इसलिए क़ुएउ के empty का प्रोग्राम है |
#include<conio.h>
#include<studio.h>
void is_empty( struct Queue);
struct employee
{
int salary;
struct employee *address;
}head;
struct Queue
{
int *front;
int *rear;
int count ;
}q1;
void main()
{
q1->front=NULL;
q1->front=NULL;
q1->front=NULL;
is_empty( q1);
getch();
}
void is_empty(Queue *q)
{
if(q->rear == NULL)
{
printf(“Queue is empty “);
}
else
{
printf(“Queue is not empty “);
}
}
इसके अलावा Queue मे data insert और data डिलीट का operation भी perform होता है |इसके algorithm और प्रोग्राम code नीचे है |
1.EnQueue
किसी Queue मे नए data को add करने के प्रोसेस को EnQueue कहते है |इसके अलोरिथ्म होती है :-
1.सबसे पहले एक node variable declare किया जाता है |जिसका नाम ‘t’ होता है |
2.इस variable मे dynamic memory allocation से allocate memory के address assign होता है |
3.उसके बाद , इस variable के item field मे data को assign किया जाता है |
4.फिर condition check की जाती है |
5.अगर Queue empty होती है तब दोनों pointer front और rear ,इस variable ‘t’ को point करते है |
अन्यथा Queue के rear pointer इस new variable ‘t’ को point करेगा |और इस नए variable को rear बना देते है |
6.counter variable ‘c’ मे increment हो जाता है |
2.DeQueue
इस operation मे ,front से data को डिलीट करते है और value को return करते है |इसके लिए नया front node ,current node के अगले वाले node को point करेगा |लेकिन येसा करने पर current node को access नहीं कर सकते है |इसलिए सबसे पहेले , एक temperory node को declare किया जाता है |जिसमे current node के address को store किया जाता है |बाद मे इसे free() function से डिलीट कर दिया जाता है |
1.Temporary node को बनाया जाता है |
2. ये Temporary node , Queue के front node को point करता है |
3. Temporary node के item feild मे store data को variable मे store कर दी जाती है |
4.इसके बाद front pointer ,current node से next node को point करता है |
5.Temporary node को डिलीट कर देते है |
Source Code :
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
#define SIZE 10
void initialize(queue *q1);
int is_empty(queue *q1);
void enqueue(queue *q1, int value);
int dequeue(queue *q1);
void display(employee *h);
struct employee
{
int salary;
struct employee *next;
}employee;
struct queue
{
int count;
employee *front;
employee *rear;
}queue;
int main()
{
queue *q1;
q1 = malloc(sizeof(queue));
initialize(q1);
enqueue(queue *q1, 120);
enqueue(queue *q1, 230);
enqueue(queue *q1, 345);
enqueue(queue *q1, 255);
printf(“queue before delete operation \n”);
display(q1->front);
dequeue(q1);
printf(“queue after delete operation\n”);
display(q1->front);
getch();
}
void initialize(queue *q1)
{
q1->count = 0;
q1->front = NULL;
q1->rear = NULL;
}
int is_empty(queue *q1)
{
return (q1->rear == NULL);
}
void enqueue(queue *q1, int value)
{
if (q1->count < SIZE)
{
employee *t;
t = malloc(sizeof(employee));
t->salary = value;
t->next = NULL;
if(!isempty(q1))
{
q1->rear->next = t;
q1->rear = t;
}
else
{
q1->front = q1->rear = t;
}
q1->count++;
}
else
{
printf(“List is full\n”);
}
}
int dequeue(queue *q1)
{
employee *t;
int n = q1->front->salary;
t = q1->front;
q1->front = q1->front->next;
q1->count–;
free(t);
return(n);
}
void display(employee *h)
{
if(h == NULL)
{
printf(“NULL\n”);
}
else
{
printf(“%d\n”, h -> salary);
display(h->next);
}
}
इस प्रोग्राम मे , पांच function को use किया गया है :-
void initialize(queue *q1): इस function का use ,queue के तीन element front ,rear और count को initial करने के लिए किया गया है |
int is_empty(queue *q1): इस function से ,queue के emptyness को check किया गया है |अगर queue empty है तब null value return होगी |
void enqueue(queue *q1, int value): इससे queue मे data को add किया गया है |
int dequeue(queue *q1): इससे queue मे data को डिलीट किया गया है |
void display(employee *h): इस function का use ,queue के सभी data को display करने के लिए किया जाता |
main() मे ,
enqueue(queue *q1, 120); इस statement से , queue के front position पर 120 insert होगी |
enqueue(queue *q1, 230); इस statement से , queue के front position पर 230 insert होगी |
enqueue(queue *q1, 345); इस statement से , queue के front position पर 345 insert होगी |
enqueue(queue *q1, 255); इस statement से , queue के front position पर 255 insert होगी |
आउटपुट होगा :-
queue before delete operation
120
230
345
255
queue after delete operation
230
345
255
Recent Posts
मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi
malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…
कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए
राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…
हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained
hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…
तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second
Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…
चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi
chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…
भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi
first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…