-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQ6.c
60 lines (60 loc) · 1014 Bytes
/
Q6.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
#include<stdio.h>
#include<malloc.h>
struct node
{
int info;
struct node *next;
};
struct node *start=NULL,*last=NULL;
void insert()
{
struct node *t = (struct node*)malloc(sizeof(struct node));
printf("Enter Info: ");
scanf("%d",&t->info);
t->next = NULL;
if(start == NULL)
{
start = t;
last = t;
}
else
{
last->next = t;
last = t;
}
}
void display()
{
if(start==NULL)
{
printf("LL is Empty!");
return;
}
struct node *t = start;
while(t!=NULL)
{
printf("%d ",t->info);
t = t->next;
}
printf("\n");
}
void ret(struct node *t)
{
if(t==NULL)
return;
else
{
printf("%d ",t->info);//for forward print
ret(t->next);
printf("%d ",t->info);//for backward print
}
};
void main()
{
for(int i=0; i<6;i++)
{
insert();
}
display();
ret(start);
}