-
Notifications
You must be signed in to change notification settings - Fork 0
/
singley linkedlist with insertion searching deletion.cpp
84 lines (67 loc) · 1.49 KB
/
singley linkedlist with insertion searching deletion.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
#include<iostream>
#include<cstdlib>
using namespace std;
typedef struct linkedlist
{
int data;
struct linkedlist *next;
} node;
void insert(node *s,int data) //insert function
{
while(s->next !=NULL)
{
s=s->next;
}
s->next=(node*)malloc(sizeof(node));
s->next->data=data;
s->next->next=NULL;
}
void search(node *s,int data) //searching function
{
int count=0;
while(s->next !=NULL)
{
if(s->next->data==data)
{
count++;
}
s=s->next;
}
cout<<"total"<<" "<<count<<" "<<"result found"<<endl;
}
void deleteNode(node *s,int data) //delete function
{
while(s->next != NULL)
{
if(s->next->data==data)
{
s->next=s->next->next;
return;
}
s=s->next;
}
}
void display(node *s) //display function
{
while(s->next != NULL)
{
cout<<s->next->data<<endl;
s = s->next;
}
}
int main()
{
node *first = (node*) malloc(sizeof(node));
first->next=NULL;
insert(first, 9);//data insertion
insert(first, 5);//data insertion
insert(first, 7);//data insertion
insert(first, 3);//data insertion
insert(first, 8);//data insertion
insert(first, 6);//data insertion
display(first);//display data
search(first, 7);//search data
deleteNode(first, 8);//delete data
display(first);//display data
return 0;
}