-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathh4q3.c
70 lines (68 loc) · 1.37 KB
/
h4q3.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
# include <stdio.h>
# include <stdlib.h>
struct nodeh43
{
int data;
struct nodeh43* next;
}*headh43 = NULL,*tailh43 = NULL;
void printh43(struct nodeh43 *h)
{
if(h == NULL)
{
printf("LIST IS EMPTY\n");
}
while(h != NULL)
{
printf("%d\t", h->data);
h = h-> next;
}
}
void revh43(int m)
{
struct nodeh43 *ptr,*prev;
ptr = prev = headh43;
for(int j=0;j<m-1;j++)
{
int i=0;
while(i < j+1)
{
prev = ptr;
ptr = ptr -> next;
i++;
}
prev->next = ptr->next;
ptr->next = headh43;
headh43 = ptr;
// printh43(headh43);
// printf("\n");
}
}
int h4q3()
{
struct nodeh43 *curr;
printf("\t\tCREATING THE LIST\n\n");
int n;
printf("ENTER NUMBER OF NODES : ");
scanf("%d",&n);
printf("ENTER THE ELEMENTS : ");
for(int i=0;i<n;i++)
{
curr= malloc(sizeof(struct nodeh43));
curr -> next = NULL;
scanf("%d",&curr->data);
if(headh43 == NULL)
{
headh43 = tailh43 = curr;
}
else
{
tailh43 -> next = curr;
tailh43 = curr;
}
}
int m;
printf("ENTER THE VALUE OF M: ");
scanf("%d",&m);
revh43(m);
printh43(headh43);
}