-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path4. Linkedlist.cpp
67 lines (65 loc) · 1.27 KB
/
4. Linkedlist.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
#include<iostream>
#include<stdlib.h>
using namespace std;
class list{
int data;
list *next;
public:
void insert();
void del();
void display();
}*newnode,*head=NULL,*temp;
void list::insert()
{
newnode = new list;
cout<<"Enter the data:";
cin>>newnode ->data;
newnode ->next =NULL;
if(head==NULL)
{
temp=head=newnode;
}
else
{
newnode->next=head;
head=newnode;
}
}
void list::del()
{
temp=head;
cout<<"The Deleted element is:"<<temp->data;
head=temp->next;
delete temp;
}
void list:: display()
{
cout<<"Elements in the list are:";
temp=head;
while(temp!=NULL)
{
cout<<temp->data<<" ";
temp=temp->next;
}
}
int main()
{
list l;
int ch;
while(1){
cout<<"\nLinked list Operations:-\n";
cout<<"1.Insert front\n";
cout<<"2.Delete front\n";
cout<<"3.Display\n";
cout<<"4.Exit\n";
cout<<"Enter your choice :";
cin>>ch;
switch(ch){
case 1:l.insert();break;
case 2:l.del();break;
case 3:l.display();break;
case 4:exit(0);
default :cout<<"Invalid Choice!!\n";
}
}
}