-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathll.c
More file actions
38 lines (31 loc) · 681 Bytes
/
ll.c
File metadata and controls
38 lines (31 loc) · 681 Bytes
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
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int num;
struct node *next;
} nodet;
nodet *insert(nodet *head, int number) {
nodet *ptr = (nodet *)malloc(sizeof(nodet));
if (ptr == NULL) {
fprintf(stderr, "Error: Malloc unsuccessful.");
exit(0);
}
ptr->num = number;
ptr->next = head;
return ptr;
}
void print_ll(nodet *head) {
printf("----------\n");
for (nodet *p = head; p != NULL; p = p->next) {
printf("%d\n", p->num);
}
}
int main() {
nodet *head = NULL;
int data;
while(scanf("%d", &data) == 1) {
head = insert(head, data);
}
print_ll(head);
return 0;
}