forked from Subhajitroy03/DSA-3rdSem-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue(linkedlist).cpp
More file actions
97 lines (96 loc) · 1.64 KB
/
Copy pathQueue(linkedlist).cpp
File metadata and controls
97 lines (96 loc) · 1.64 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
90
91
92
93
94
95
96
97
#include<iostream>
using namespace std;
class Node{
public:
int data;
Node* next;
Node(int data){
this->data=data;
this->next=NULL;
}
};
class SLL{
public:
Node* head;
SLL(){
head=NULL;
}
bool isEmpty(){
return(head==NULL);
}
void addBeg(int d){
Node* temp=new Node(d);
if(!isEmpty()){
temp->next=head;
}
head=temp;
}
void display(){
if(!isEmpty()){
Node* temp=head;
while(temp!=NULL){
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<endl;
}
}
void push(int d){
if(isEmpty()){
addBeg(d);
return;
}
Node* ptr=new Node(d);
Node* temp=head;
while(temp->next!=NULL){
temp=temp->next;
}
temp->next=ptr;
}
void pop(){
if(!isEmpty()){
Node* temp=head;
head=head->next;
delete(temp);
}
}
int peek(){
return(head->data);
}
};
int main(void){
SLL list;
while(1){
int ch;
cout << "Menu:\n" <<
"(1) Push" << endl <<
"(2) Pop" << endl <<
"(3) Display" << endl <<
"(4) Peek" << endl <<
"(5) isEmpty" << endl <<
"(6)Exit"<<endl;
cout<<"Enter your choice: ";
cin>>ch;
int element;
if(ch==1){
cout<<"Enter element: ";
cin>>element;
list.push(element);
}else if(ch==2){
list.pop();
}else if(ch==3){
cout<<"The Queue list: "<<endl;
list.display();
}else if(ch==4){
cout<<"The front element: "<<list.peek()<<endl;
}else if(ch==5){
if(list.isEmpty()){
cout<<"The Queue is empty... "<<endl;
}else{
cout<<"The Queue is not empty... "<<endl;
}
}else if(ch==6){
break;
}
}
}