-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDoubleIt.c
More file actions
65 lines (57 loc) · 1.16 KB
/
DoubleIt.c
File metadata and controls
65 lines (57 loc) · 1.16 KB
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
#include "logic.c"
Node *doubleIt(Node *head)
{
Node *p = head;
if (head->next == NULL)
{
p->data = p->data * 2;
if (p->data >= 10)
{
Node *nn = (Node *)malloc(sizeof(Node));
nn->data = 1;
nn->next = p;
head = nn;
}
return head;
}
Node *q = p->next;
if (head->data * 2 >= 10)
{
Node *nn = (Node *)malloc(sizeof(Node));
nn->data = 1;
nn->next = p;
head = nn;
}
while (q != NULL)
{
if (q->data >= 5)
{
printf("%d ", p->data);
p->data = (p->data * 2 + 1) % 10;
}
else
{
printf("%d ", p->data);
p->data = p->data * 2 % 10;
}
p = p->next;
q = q->next;
printf("%p \n",q);
}
// p = p->next;
printf("%d ", p->data);
p->data = (p->data * 2) % 10;
return head;
}
int main(int argc, char const *argv[])
{
Node *head;
init(&head);
append(&head, 1);
append(&head, 8);
append(&head, 9);
display(head);
head = doubleIt(head);
display(head);
return 0;
}