-
Notifications
You must be signed in to change notification settings - Fork 22
/
Queue(LL).cpp
77 lines (74 loc) · 1.16 KB
/
Queue(LL).cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
typedef struct queue
{
int data;
struct queue* prev;
}q;
q* rear=NULL;
q* front=NULL;
void enQueue()
{
q *temp=(q*)malloc(sizeof(q));
if(temp==NULL)
{
printf("\nOut of Memory Space:\n");
return;
}
printf("\nEnter the data:\t" );
scanf("%d",&temp->data);
temp->prev =NULL;
if(rear==NULL)
{
rear=temp;
front=temp;
return;
}
rear->prev=temp;
rear=temp;
return;
}
void deQueue()
{
q *ptr;
if(rear==NULL)
{
cout<<"\nEmpty Queue";
return;
}
ptr=front;
cout<<"\nDeleted data: "<<front->data;
front=ptr->prev;
return;
}
void print(q *ptr)
{
if(rear==NULL)
{
printf("\nList is empty:\n");
return;
}
else
{
ptr=front;
printf("\nThe List elements are:\n");
while(ptr!=NULL)
{
printf("%d\t",ptr->data);
ptr=ptr->prev ;
}
}
}
int main()
{
int n;
printf("Enter the range: ");
cin>>n;
for(int i=0;i<n;i++)
enQueue();
print(front);
deQueue();
print(front);
}