-
Notifications
You must be signed in to change notification settings - Fork 0
/
SLL.cpp
69 lines (69 loc) · 1.11 KB
/
SLL.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
#include <iostream>
#include <stdio.h>
#include <conio.h>
struct node
{
int data;
node *next;
}*front=NULL,*rear=NULL, *ptr = NULL, *np = NULL;
void push(int x)
{
np=new node;
np->data=x;
np->next=NULL;
if(front==NULL)
{
front=rear=np;
rear->next = NULL;
}
else
{
rear->next=np;
rear=np;
rear->next=NULL;
}
}
int remove()
{
int x;
if (front==NULL)
{
cout<<"empty queue\n";
}
else
{
ptr=front;
x=ptr->data;
front=front->next;
delete(ptr);
return(x);
}
}
void main()
{
int n,c=0,x;
cout<<"Enter the number of values to be pushed into queue\n";
cin>>n;
while(c<n)
{
cout<<"Enter the value to be entered into queue\n";
cin>>x;
push(x);
c++;
}
cout<<"\n\nRemove Value?\n\n";
char rem;
rem='Y';
while(rem=='y'||rem--'Y')
{
cin>>rem;
if(front==NULL)
break;
if(rem='Y'||rem='y')
{
if(front != NULL)
cout<<remove()<<"\n";
}
}
getch();
}