-
Notifications
You must be signed in to change notification settings - Fork 0
/
REV.CPP
140 lines (109 loc) · 1.83 KB
/
REV.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
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
#include<iostream.h>
#include<conio.h>
#include<malloc.h>
class cll
{ struct node
{
int data;
node *next;
};
node *start;
node *last;
public:
void input();
void display();
void reverse();
void del();
struct node *t;
node* create()
{
node *nnd;
nnd=(node *)malloc(sizeof(node));
return nnd;
}
}obj;//class ends
cll:: node *start=NULL;
void cll::reverse()
{
node *current,*next,*prev;
current =start;
prev=NULL;
while(current!=NULL)
{
next=current->next;
current->next=prev;
prev=current;
current=next;
}
start=prev;
int a=0;
node *rev;
rev=start;
while(rev!=NULL)
{
cout<<rev->data;
rev=rev->next;
if(a>10){break;}
a++;
}
}
void cll::del()
{
node *del;
node *ptr;
ptr=obj.start;
while(ptr->next!=NULL)
{ del=ptr;
ptr=ptr->next;
}
//free(ptr);
del->next=NULL;
free(ptr);
}
void cll:: input()
{
node *in; node *trav;
in =create();
last=in;
cout<<"enter the data ";
cin>>in->data;
in->next=NULL;
if(start==NULL)
{ start=in;
}
else
{
trav=start;
while(trav->next!=NULL)
{
trav=trav->next;
}
trav->next=in;
}
}
void cll:: display()
{
node *prnt;
prnt=start;
while(prnt->next!=NULL)
{
cout<<prnt->data;
prnt=prnt->next;
}
cout<<prnt->data<<endl;
}
void main()
{
int ele;
clrscr();
cout<<"enter the no of ele you want ";
cin>>ele;
for(int i=0;i<ele;i++)
{
obj.input();
}
cout<<endl;
obj.display();
obj.reverse();
getch();
}