-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathQueue(CLL).cpp
More file actions
89 lines (85 loc) · 1.36 KB
/
Queue(CLL).cpp
File metadata and controls
89 lines (85 loc) · 1.36 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
#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 && front==NULL)
{
front=rear=temp;
rear->prev=front;
}
else
{
rear->prev=temp;
rear=temp;
temp->prev=front;
}
}
void deQueue()
{
q *ptr=front;
if(rear==NULL && front==NULL)
{
cout<<"\nEmpty Queue";
return;
}
else if(front==rear)
{
front=rear=NULL;
free(ptr);
}
else
{
cout<<"\nDeleted data: "<<front->data;
front=front->prev;
rear->prev=front;
free(ptr);
}
}
void print(q *ptr)
{
if(rear==NULL && front==NULL)
{
printf("\nList is empty:\n");
return;
}
else
{
ptr=front;
printf("\nThe List elements are:\n");
while(ptr->prev!=front)
{
printf("%d\t",ptr->data);
ptr=ptr->prev ;
}
printf("%d\t",ptr->data);
}
}
int main()
{
int n;
printf("Enter the range: ");
cin>>n;
for(int i=0;i<n;i++)
enQueue();
print(front);
deQueue();
print(front);
}