-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedListForMam.cpp
More file actions
167 lines (153 loc) · 2.62 KB
/
LinkedListForMam.cpp
File metadata and controls
167 lines (153 loc) · 2.62 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
struct node
{
int data;
node *next;
};
struct node *p,*ex,*start=NULL,*temp,*t,*l;
void Creat_Node()
{
int value;
cin >> value;
temp=new node;
temp->data=value;
temp->next=NULL;
}
void Insert()
{
Creat_Node();
if(start==NULL)
{
start=temp;
}
else
{
p=start;
while(p->next != NULL)p=p->next;
p->next=temp;
}
}
void Show()
{
p=start;
while(p!=NULL)
{
cout <<p->data<<"-->";
p=p->next;
}
cout <<"NULL"<<endl<<endl;
}
void Search()
{
p=start;
int srch;
bool b=0;
cout <<"Enter the searching element"<<endl;
cin >> srch;
while(p!=NULL)
{
if(srch==p->data)
{
b=1;
break;
}
p=p->next;
}
if(b)cout <<p->data<<" The element is found"<<endl;
else cout <<"Not found"<<endl;
}
void Insert_Position()
{
p=start;
int i=0;
while(p!=NULL)
{
i++;
p=p->next;
}
p=start;
cout <<"Enter ur position"<<endl;
int pos;
cin >>pos;
if(i>=pos)
{
Creat_Node();
if(pos==0)
{
ex=start;
start=temp;
temp->next=ex;
}
else
{
for(int i=0; i<pos; i++)
{
ex=p;
p=p->next;
}
temp->next=p;
ex->next=temp;
}
}
else cout <<"Does not possible"<<endl;
}
void Delete()
{
cout <<"Enter element for Delete"<<endl;
int d,i=0;
cin >> d;
p=start;
while(d !=p->data)
{
i++;
ex=p;
p=p->next;
}
if(i==0)
{
start=p->next;
}
else
ex->next=p->next;
}
void Sort()
{
p=start;
for(ex=p; ex->next != NULL; ex=ex->next)
{
for(t=ex->next; t!=NULL; t=t->next)
{
if(ex->data>t->data)
{
int temp=ex->data;
ex->data=t->data;
t->data=temp;
}
}
}
}
int main()
{
cout<<"Enter your choice Sadik Vai "<<endl;
int choice ;
Insert(8);
Insert(2);
Insert(3);
Insert(4);
Insert(1);
Insert(5);
Insert(6);
Insert(7);
Show();
Search();
Insert_Position();
Show();
Delete();
Show();
Sort();
cout <<"After Sorting"<<endl;
Show();
return 0;
}