-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlinkedlist.c
More file actions
64 lines (51 loc) · 1.16 KB
/
linkedlist.c
File metadata and controls
64 lines (51 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
#include <stdio.h>
#include <stdlib.h>
int commandNumber = 0;
struct node *head_job = NULL;
struct node *current_job = NULL;
void addToJobList();
void display(struct node *tmp);
struct node {
int number;
struct node *next;
struct node *prev;
}
void addToJobList() {
struct node *job = malloc(sizeof(struct node));
//If the job list is empty, create a new head
if (head_job == NULL) {
job->number = 1;
//the new head is also the current node
job->next = NULL;
job->prev = NULL;
head_job = job;
current_job = head_job;
}
//Otherwise create a new job node and link the current node to it
else {
job->number = current_job->number + 1;
job->prev = current_job;
current_job->next = job;
current_job = job;
job->next = NULL;
}
commandNumber++;
printf("\njob: [%d]\n", job->number);
}
void display(struct node *tmp) { //treverse jobs linked list
if(tmp == NULL) {
printf("EMPTY LIST!\n");
return;
}
printf("[%d]\t\n", tmp->number);
if (tmp->next == NULL) return;
display(tmp->next);
}
int main() {
struct node *test = head_job;
addToJobList();
display(test);
addToJobList();
display(test);
return 0;
}