-
Notifications
You must be signed in to change notification settings - Fork 0
/
p6.cpp
115 lines (74 loc) · 1.5 KB
/
p6.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <iostream>
using namespace std;
class node {
public:
int data;
node* next;
node(int value){
data = value;
next=NULL;
}
};
node* insertAthead(node** head_ref, int val1){
node*n1 = new node(val1);
node* head;
head = *head_ref;
if(head==NULL){
n1->next==NULL;
}
n1->next=head;
head=n1;
return head;
}
void insertAtend(node** head_ref, int val){
node* n= new node(val);
node* head;
head = *head_ref;
if(head==NULL){
head=n;
n->next=NULL;
return;
}
node* temp;
temp=head;
while(temp->next!=NULL){
temp=temp->next;
}
temp->next=n;
n->next=NULL;
}
void deletion(node** head_ref, int val){
node* head;
head = *head_ref;
node* temp;
temp=head;
node* todel;
while(temp->next->data!=val){
temp=temp->next;
}
todel=temp->next;
temp->next = temp->next->next;
delete todel;
}
void print(node* head){
node* temp1;
temp1=head;
while(temp1!=NULL){
cout<< temp1->data<<endl;
temp1=temp1->next;
}
}
int main()
{
cout<<"Hello World";
node* head;
head = new node(10);
node** head_ref1;
head_ref1= &head;
head=insertAthead(head_ref1, 40);
insertAtend(head_ref1 , 20);
insertAtend(head_ref1 , 30);
deletion(head_ref1 , 20);
print(head);
return 0;
}