-
Notifications
You must be signed in to change notification settings - Fork 1
/
Q2.c
73 lines (73 loc) · 1.24 KB
/
Q2.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
72
73
#include<stdio.h>
#include<malloc.h>
struct node
{
int info;
struct node *prev;
struct node *next;
};
struct node *start = NULL,*last = NULL;
void insert()
{
struct node *q = (struct node*)malloc(sizeof(struct node));
printf("Enter Data: ");
scanf("%d",&q->info);
q->next = NULL;
q->prev = NULL;
if(start == NULL)
{
q->prev = NULL;
start = q;
last = q;
}
else
{
q->prev = last;
last->next = q;
last = q;
}
}
void display()
{
struct node *t = start;
if(start=NULL)
{
printf("LL is Empty!");
return;
}
while(t!=NULL)
{
printf("%d ",t->info);
t = t->next;
}
printf("\n");
}
void showinfo(int n)
{
struct node *q = last;
if(n<0)
{
printf("Wrong Input!\n");
return;
}
for(int i=1;i<n;i++)
{
if(q->prev==NULL)
{
printf("Wrong Input!");
return;
}
q = q->prev;
}
printf("Data of %d last node: %d\n",n,q->info);
}
void main()
{
insert();
insert();
insert();
insert();
insert();
display();
showinfo(9);
}