- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinked.cpp
More file actions
Latest commit
47 lines (45 loc) · 749 Bytes
/
Copy pathLinked.cpp
File metadata and controls
47 lines (45 loc) · 749 Bytes
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
#include<iostream>
usingnamespacestd;
structNode{
int data;
Node* next;
};
voidInsert(Node **head_ref,int new_data)
{
Node *new_node=newNode();
new_node->data=new_data;
new_node->next=(*head_ref);
(*head_ref)=new_node;
}
voiddele(Node **head_ref,int item)
{
Node *temp = *head_ref;
Node *prev = *head_ref;
while(temp->data!=item &&temp->next!=NULL)
{
prev=temp;
temp=temp->next;
}
prev->next=temp->next;
delete(temp);
}
voidprint(Node *n)
{
while(n!=NULL)
{
cout<<n->data<<"";
n=n->next;
}
}
intmain()
{
Node *head=newNode();
Insert(&head,5);
Insert(&head,55);
Insert(&head,56);
Insert(&head,57);
print(head);
cout<<"\n";
dele(&head,55);
print(head);
}