forked from rk2279709/DSA-Linked-List-Assignment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ7.c
86 lines (85 loc) · 1.42 KB
/
Q7.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
74
75
76
77
78
79
80
81
82
83
84
85
86
#include<stdio.h>
#include<malloc.h>
struct node
{
int info;
struct node *prev;
struct node *next;
}*start=NULL,*last=NULL;
int num = 0;
void insert()
{
struct node *t = (struct node*)malloc(sizeof(struct node));
printf("Enter Data: ");
scanf("%d",&t->info);
t->prev = NULL;
t->next = NULL;
if(start==NULL)
{
num++;
start = t;
last = t;
}
else
{
num++;
t->prev = last;
last->next = t;
last = t;
}
}
void display()
{
if(start==NULL)
{
printf("LL is empty!\n");
return;
}
struct node *t = start;
while(t!=NULL)
{
printf("%d ",t->info);
t = t->next;
}
printf("\n");
}
void rev(int n)
{
if(n==1)
return;
else if(n == num)
{
struct node *p1 = start;
struct node *p2 = p1->next;
struct node *p3 = p2->next;
p1->next = NULL;
p2->next = p1;
while(p3!=NULL)
{
p1 = p2;
p2 = p3;
p3 = p3->next;
p2->next = p1;
}
start = p2;
}
else
{
if(n%2==0)
{
struct node *p1,*p2;
}
}
}
void main()
{
insert();
insert();
insert();
insert();
insert();
insert();
display();
rev(6);
display();
}