-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP1.C
71 lines (66 loc) · 1.32 KB
/
P1.C
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
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
typedef struct node
{
int info;
struct node *next;
}nodetype;
void insert(nodetype **l,nodetype **r)
{ nodetype *p;int n;
p=(nodetype*)malloc(sizeof(nodetype));
printf("ENTER THE ELEMENTS\n");
scanf("%d",&n);
p->info=n;
if(*l==NULL)
{
*l=p;
*r=*l;
}
else
{
(*r)->next=p;
*r=p;
}
}
nodetype *reverse(nodetype *l,nodetype **tp)
{int m;
nodetype *t;
t=(nodetype*)malloc(sizeof(nodetype));
t->info=l->info;
t->next=*tp;
*tp=t;
m=(*tp)->info;
l=l->next;
if(l==NULL)
return(1);
else
return(reverse(l,&tp));
}
void display(nodetype *tp)
{int m;
while(tp!=NULL)
{
m=tp->info;
printf("%d",m);
tp=tp->next;
}
}
void main()
{
nodetype *l=NULL;int c; nodetype *tp=NULL;
nodetype *r=NULL;
printf("ENTER 1 TO INSERT AND 2 TO REVERSE\n ");
do
{
scanf("%d",&c);
switch(c)
{
case 1:insert(&l,&r);
break;
case 2:reverse(l,&tp);
display(tp);
}
}while(c!=3);
getch();
}