-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathh4q7.c
85 lines (80 loc) · 1.64 KB
/
h4q7.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
# include <stdio.h>
# include <stdlib.h>
struct nodeh47
{
int data;
struct nodeh47* next;
}*headh47 = NULL,*tailh47 = NULL;
void printh47(struct nodeh47 *h)
{
if(h == NULL)
{
printf("LIST IS EMPTY\n");
}
while(h != NULL)
{
printf("%d\t", h->data);
h = h-> next;
}
}
void swaph47(int *a,int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
void arrangeh47(struct nodeh47 *headh47)
{
struct nodeh47 *temp = headh47, *ptr = headh47->next;
while(ptr->next != NULL)
{
if(temp->data % 2 == 1)
{
while(ptr != NULL && ptr->data%2 ==1)
{
ptr = ptr->next;
}
if(ptr == NULL)
{
break;
}
else
{
swaph47(&temp->data , &ptr->data);
}
temp = temp->next;
}
else
{
temp = temp->next;
ptr = ptr->next;
}
}
}
int h4q7()
{
struct nodeh47 *curr;
printf("\t\tCREATING THE LIST\n\n");
int n;
printf("ENTER NUMBER OF NODEh47S : ");
scanf("%d",&n);
printf("ENTER THE ELEMENTS : ");
for(int i=0;i<n;i++)
{
curr= malloc(sizeof(struct nodeh47));
curr -> next = NULL;
scanf("%d",&curr->data);
if(headh47 == NULL)
{
headh47 = tailh47 = curr;
}
else
{
tailh47 -> next = curr;
tailh47 = curr;
}
}
arrangeh47(headh47);
printh47(headh47);
return 0;
}