/
linkedlist.c
69 lines (54 loc) · 1.12 KB
/
linkedlist.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
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int data;
struct node *next;
} node_t;
node_t* new_node(node_t* nxt, int data){
node_t *tmp = (node_t*)malloc(sizeof(node_t));
tmp->next = nxt;
tmp->data = data;
return tmp;
}
node_t* append_tail(node_t *list, int data) {
if (list == NULL) {
list = new_node(NULL,-123);
puts("List was null, created new node.");
return list;
}
node_t *current = list;
node_t *temp;
while (current->next != NULL) {
current = current->next;
}
temp = new_node(NULL, data);
current->next = temp;
temp->data = data;
return list;
}
void printlist(node_t *head){
while (head != NULL) {
printf("%d\n",head->data);
head = head->next;
}
}
node_t* append_head(node_t *head, int data){
node_t *tmp = new_node(head,data);
return tmp;
}
node_t* deQ(node_t *head){
node_t *tmp = head;
}
int main(int argc,char **argv){
int i;
node_t *list = NULL;
puts("Testing linked list.");
for (i = 0; i < 10; i++) {
/* append_head(list,i); */
list = append_tail(list,i);
list = append_head(list,i);
}
puts("Printing:");
printlist(list);
return EXIT_SUCCESS;
}