queue using linked list c 2b 2b

Solutions on MaxInterview for queue using linked list c 2b 2b by the best coders in the world

showing results for - "queue using linked list c 2b 2b"
Jessica
13 Jul 2017
1/*
2 * Program  : Queue using linked list
3 * Language : C
4 */
5
6#include<stdio.h>
7#include<stdlib.h>
8
9struct node
10{
11    int data;
12    struct node *next;
13};
14
15struct node *front = NULL, *rear = NULL;
16
17void enqueue(int val)
18{
19    struct node *newNode = malloc(sizeof(struct node));
20    newNode->data = val;
21    newNode->next = NULL;
22
23    //if it is the first node
24    if(front == NULL && rear == NULL)
25        //make both front and rear points to the new node
26        front = rear = newNode;
27    else
28    {
29        //add newnode in rear->next
30        rear->next = newNode;
31
32        //make the new node as the rear node
33        rear = newNode;
34    }
35}
36
37void dequeue()
38{
39    //used to free the first node after dequeue
40    struct node *temp;
41
42    if(front == NULL)
43         printf("Queue is Empty. Unable to perform dequeue\n");
44    else
45    {
46        //take backup
47        temp = front;
48
49        //make the front node points to the next node
50        //logically removing the front element
51        front = front->next;
52
53        //if front == NULL, set rear = NULL
54        if(front == NULL)
55            rear = NULL;
56
57       //free the first node
58       free(temp);
59    }
60
61}
62
63void printList()
64{
65    struct node *temp = front;
66
67    while(temp)
68    {
69        printf("%d->",temp->data);
70        temp = temp->next;
71    }
72    printf("NULL\n");
73}
74
75int main()
76{
77    enqueue(10);
78    enqueue(20);
79    enqueue(30);
80    printf("Queue :");
81    printList();
82    dequeue();
83    printf("After dequeue the new Queue :");
84    printList();
85    dequeue();
86    printf("After dequeue the new Queue :");
87    printList();
88
89    return 0;
90}
91
Clay
19 Jan 2020
1/*
2 * Program  : Queue using linked list
3 * Language : C
4 */
5
6#include<stdio.h>
7#include<stdlib.h>
8
9struct node
10{
11    int data;
12    struct node *next;
13};
14
15struct node *front = NULL, *rear = NULL;
16
17void enqueue(int val)
18{
19    struct node *newNode = malloc(sizeof(struct node));
20    newNode->data = val;
21    newNode->next = NULL;
22
23    //if it is the first node
24    if(front == NULL && rear == NULL)
25        //make both front and rear points to the new node
26        front = rear = newNode;
27    else
28    {
29        //add newnode in rear->next
30        rear->next = newNode;
31
32        //make the new node as the rear node
33        rear = newNode;
34    }
35}
36
37void dequeue()
38{
39    //used to free the first node after dequeue
40    struct node *temp;
41
42    if(front == NULL)
43         printf("Queue is Empty. Unable to perform dequeue\n");
44    else
45    {
46        //take backup
47        temp = front;
48
49        //make the front node points to the next node
50        //logically removing the front element
51        front = front->next;
52
53        //if front == NULL, set rear = NULL
54        if(front == NULL)
55            rear = NULL;
56
57       //free the first node
58       free(temp);
59    }
60
61}
62
63void printList()
64{
65    struct node *temp = front;
66
67    while(temp)
68    {
69        printf("%d->",temp->data);
70        temp = temp->next;
71    }
72    printf("NULL\n");
73}
74
75int main()
76{
77    enqueue(10);
78    enqueue(20);
79    enqueue(30);
80    printf("Queue :");
81    printList();
82    dequeue();
83    printf("After dequeue the new Queue :");
84    printList();
85    dequeue();
86    printf("After dequeue the new Queue :");
87    printList();
88
89    return 0;
90}
queries leading to this page
how to represent a queue using linked listprogram to implement a queue using linked list in cexplain linked list implementation of queue name program in queue in c 2b 2b using linked listlinked list implementation of queue in c 2b 2bimplement queue using doubly linked list c 2b 2bimplementation of queue using array and linked list in ccan you implement queue using linked lists 3fqueue using linked lisyt c 2b 2bqueue using linked list in cqueue linked list representation c 2b 2bqueue implementation linked listimplement a queue using linked listc queue on linked listlinked list using queuehow to make a queue to maintain using linked list in cto write a c 2b 2b program for queue using linked implementation queue uusing linked listhow to sort queues with linked list in cqueue using linked list 2awrite a program to implement queue operations using linked listqueue made from a linked listqueue using a linked list c 2b 2bqueue using linked list c 2b 2blinked queue c 2b 2bqueue linked list program in cprogram to implement queue using linked listsimple queue implementation using linked list c 2b 2b gfgqueue using linked list cppqueue singly linked list cqueue using linked listsimplement queue as linked listc program to implement queue using linked listslinkedlist implementation of queuequeue linked list chow to make a queue using linked listqueue using a linked listimplementing a queue using linked listalgorithm for queue using linked list in cqueue in c linked listqueue c implementation linked listreal life implementation of queue using linked list in c 2b 2blinked list implementation of queuec 2b 2b queue implementation using linked listlinked list with queuequeue in c using linked listimplement queue using linked list geeksforgeeksalgorithm for queue using linked list in c 5c 5clinked list in queuequeue e2 80 93 linked listis queues doubly linked list are implementation in c data structuresingly linked list queue in c languagequeue using linked list cqueue as linked list cc 2b 2b program to implement queue using linked listqueue linkedlistqueue c 2b 2b implementation linked listqueue using linked list in c programming9c program to perform all operations related with queue as linked listsimple c fifo queues linked listqueue through linkedlistcode a c program to implement queue adt using linked listimplementation of queue using linked list in c 2b 2bhow to create queue using linked listlinked list queue in clinked list implementation of queue in data structure cimplement queue using linked list in c 2b 2bimplement a queue in c using a singly linked list queue using linked list in c 2b 2bwrite a program to implement queue using linked listimplement queue using linked list in cimplement queue using linked list c 2b 2b queue linked list exampleimplement a queue using a linked listlinked list queuelinked list stack queues linear ds in c programmingimplementation of queue using linked listqueue using linked listdo queues use linked listqueue linked list implementationqueue linked listqueue in c 2b 2b using linked listqueue implementation in c using linked listqueue using doubly linked list c 2b 2bqueue singly linked list c 2b 2bqueue as linked listimplementation of queue in linked listlinked list implementation of queue in cqueue c 2b 2b linked listqueue implementation using linked listimplement queue using linked listc queue using linked listimplementation of queue using linked list in cqueue implementation by linked listqueue using linked implementation queue using linked list c 2b 2b