-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedlist.c
More file actions
94 lines (75 loc) · 2.23 KB
/
Copy pathlinkedlist.c
File metadata and controls
94 lines (75 loc) · 2.23 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdio.h>
#include "linkedlist.h"
void llst_init(osThreadLLst_t *llst) {
llst->head = NULL;
llst->size = 0;
return;
}
void llst_destroy(osThreadLLst_t* llst) {}
uint8_t llst_size(osThreadLLst_t* llst) {
return llst->size;
}
bool llst_insertFirst(osThreadLLst_t* llst, struct osThread_t *thread_data) {
struct osThreadNode_t *newNode = (struct osThreadNode_t*) malloc(sizeof(struct osThreadNode_t));
newNode->id = llst->size;
newNode->data = thread_data;
newNode->next = llst->head; //point newNode to old first node
llst->head = newNode; //point head to newNode
llst->size++;
return true;
}
bool llst_insertLast(osThreadLLst_t* llst, struct osThread_t *thread_data) {
struct osThreadNode_t *newNode = (struct osThreadNode_t*) malloc(sizeof(struct osThreadNode_t));
newNode->id = llst->size;
newNode->data = thread_data;
newNode->next = NULL;
llst->size++;
if (llst->head == NULL) {
llst->head = newNode;
}
struct osThreadNode_t* curr = llst->head;
while(curr->next != NULL) { // walk to the end
curr = curr->next;
}
curr->next = newNode;
return true;
}
bool llst_insert_node( osThreadLLst_t* llst, struct osThread_t *thread_data, int id) {return true;}
bool list_deleteFirst( osThreadLLst_t* llst) {
struct osThreadNode_t* head = llst->head;
struct osThreadNode_t* next = head->next;
llst->head = next;
free(head);
return true;
}
bool list_deleteLast( osThreadLLst_t* llst) {
struct osThreadNode_t* curr = llst->head;
struct osThreadNode_t* next = curr->next;
while(next->next != NULL) { // walk to the end
curr = next;
next = curr->next;
}
free(next);
curr->next = NULL;
return true;
}
bool llst_delete_node( osThreadLLst_t* llst, int id) {return true;}
struct osThread_t* llst_get_node(osThreadLLst_t* llst, int id) {
struct osThreadNode_t* curr = llst->head;
//if list is empty
if(curr == NULL) {
return NULL;
}
//navigate through list
while(curr->id != id) {
//if it is last node
if(curr->next == NULL) {
return NULL;
} else {
//go to next link
curr = curr->next;
}
}
//if data found, return the current Link
return curr->data;
}