-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask13.c
43 lines (36 loc) · 786 Bytes
/
task13.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
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int val;
struct node *next;
} node;
int main() {
node *tmp, *input, *root = malloc(sizeof(node));
scanf("%d", &(root->val));
root->next = NULL;
while (!feof(stdin)) {
input = malloc(sizeof(node));
scanf("%d", &(input->val));
if (!feof(stdin)) {
if (input->val < root->val) {
input->next = root;
root = input;
} else {
for (tmp = root; tmp != NULL; tmp = tmp->next) {
if (input->val >= tmp->val && (tmp->next == NULL || (tmp-> next != NULL && input->val < tmp->next->val))) {
input->next = tmp->next;
tmp->next = input;
break;
}
}
}
}
}
while (root != NULL) {
tmp = root;
printf("%d ", tmp->val);
root = tmp->next;
free(tmp);
}
return 0;
}