-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinked.cpp
More file actions
47 lines (45 loc) · 749 Bytes
/
Linked.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>
using namespace std;
struct Node{
int data;
Node* next;
};
void Insert(Node **head_ref,int new_data)
{
Node *new_node=new Node();
new_node->data=new_data;
new_node->next=(*head_ref);
(*head_ref)=new_node;
}
void dele(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);
}
void print(Node *n)
{
while(n!=NULL)
{
cout<<n->data<<" ";
n=n->next;
}
}
int main()
{
Node *head=new Node();
Insert(&head,5);
Insert(&head,55);
Insert(&head,56);
Insert(&head,57);
print(head);
cout<<"\n";
dele(&head,55);
print(head);
}