-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab2.cpp
More file actions
91 lines (80 loc) · 952 Bytes
/
lab2.cpp
File metadata and controls
91 lines (80 loc) · 952 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
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
#include<iostream>
using namespace std;
struct node
{
int data;
node *link;
}*head;
void dispAll()
{
node *ptr=head;
while(ptr!=NULL)
{
cout<<ptr->data<<"\t";
ptr=ptr->link;
}
}
void org(node *p)
{
node *ptr=head;
while(ptr->link!=p)
{
ptr=ptr->link;
}
ptr->link =p->link;
p->link=head;
head=p;
}
void search(int val)
{
node *ptr=head;
while(ptr->data!=val&&ptr!=NULL)
{
ptr=ptr->link;
}
if(ptr==NULL)
{
cout<<"NOT FOUND"<<endl;
return;
}
org(ptr);
dispAll();
}
void insEnd(int val)
{
node *ptr = head;
node *temp= new node;
if(head==NULL)
{
temp->data=val;
temp->link=NULL;
head=temp;
return;
}
while(ptr->link!=NULL)
{
ptr=ptr->link;
}
temp->data=val;
temp->link=NULL;
ptr->link=temp;
}
int main()
{
int x=0;
while(x!= 20)
{
cout<<"Enter Number ";
cin>>x;
insEnd(x);
}
dispAll();
x=0;
while(x!=20)
{
cout<<"Enter no to search";
cin>>x;
search(x);
}
return 0;
}