-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_member_fn.cpp
85 lines (71 loc) · 1.57 KB
/
list_member_fn.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
78
79
80
81
82
83
84
85
#include <iostream>
using namespace std;
struct nod {
int info;
struct nod* next;
};
typedef struct nod node;
class list {
node* f;
public:
list() {
f = NULL;
}
void ins(int num) {
node* p = new node;
p->info = num;
p->next = f;
f = p;
cout << "Element inserted\n";
}
void del() {
node* temp = f;
if (f == NULL)
cout << "No elements to delete\n";
else {
cout << "The deleted element is " << f->info << "\n";
f = f->next;
delete temp;
}
}
void disp() {
node* temp = f;
if (f == NULL)
cout << "\nList is empty \n";
else {
cout << "\nElements in the list are:\n";
while (temp != NULL) {
cout << " " << temp->info << "\n";
temp = temp->next;
}
}
}
};
int main() {
int num, ch = 1;
list ob;
cout << "\n1-Insert 2-Delete 3-Display 4-Exit\n";
while (ch) {
cout << "Enter your choice: ";
cin >> ch;
switch (ch) {
case 1:
cout << "\nEnter element to be inserted: ";
cin >> num;
ob.ins(num);
break;
case 2:
ob.del();
break;
case 3:
ob.disp();
break;
case 4:
return 0;
default:
cout << "Invalid choice \n";
break;
}
}
return 0;
}