annotate LinkedList.c @ 38:71b465ff0622

Added support files.
author Eric Wing <ewing@anscamobile.com>
date Thu, 28 Apr 2011 16:22:30 -0700
parents 14c22fc3c753
children
rev   line source
13
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
1 #include "LinkedList.h"
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
2 #include <stddef.h> /* for NULL */
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
3 #include <stdlib.h> /* for malloc/free */
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
4 #include <stdio.h> /* for debugging */
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
5
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
6 struct LinkedListNode
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
7 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
8 LinkedListNode* nextNode;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
9 LinkedListNode* previousNode;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
10 void* dataPtr;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
11 };
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
12
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
13 struct LinkedList
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
14 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
15 size_t currentSize;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
16 LinkedListNode* headPtr;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
17 LinkedListNode* tailPtr;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
18 };
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
19
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
20
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
21 LinkedListNode* LinkedListNode_Create()
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
22 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
23 LinkedListNode* list_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
24 list_node = (LinkedListNode*)calloc(1, sizeof(LinkedListNode));
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
25 if(NULL == list_node)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
26 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
27 /* Very bad, but not sure what to do here. */
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
28 return NULL;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
29 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
30
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
31 return list_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
32 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
33
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
34
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
35 void LinkedListNode_Free(LinkedListNode* list_node)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
36 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
37 if(NULL == list_node)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
38 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
39 return;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
40 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
41 free(list_node);
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
42 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
43
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
44
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
45 LinkedList* LinkedList_Create()
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
46 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
47 LinkedList* linked_list;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
48 linked_list = (LinkedList*)calloc(1, sizeof(LinkedList));
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
49 if(NULL == linked_list)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
50 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
51 /* Very bad, but not sure what to do here. */
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
52 return NULL;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
53 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
54
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
55 return linked_list;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
56 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
57
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
58 void LinkedList_Free(LinkedList* linked_list)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
59 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
60 /* Both functions check for NULL */
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
61 LinkedList_Clear(linked_list);
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
62 free(linked_list);
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
63 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
64
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
65
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
66 /**
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
67 * Returns 1 if successful, 0 if failure.
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
68 */
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
69 unsigned int LinkedList_PushFront(LinkedList* linked_list, void* new_item)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
70 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
71 LinkedListNode* new_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
72
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
73 if(NULL == linked_list)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
74 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
75 return 0;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
76 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
77
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
78 new_node = LinkedListNode_Create();
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
79 if(NULL == new_node)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
80 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
81 return 0;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
82 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
83
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
84 new_node->dataPtr = new_item;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
85
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
86 if(0 == linked_list->currentSize)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
87 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
88 linked_list->tailPtr = new_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
89 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
90 else
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
91 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
92 LinkedListNode* head_node = linked_list->headPtr;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
93 new_node->nextNode = head_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
94 head_node->previousNode = new_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
95 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
96
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
97 linked_list->headPtr = new_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
98 linked_list->currentSize++;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
99 return 1;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
100 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
101
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
102 unsigned int LinkedList_PushBack(LinkedList* linked_list, void* new_item)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
103 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
104 LinkedListNode* new_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
105
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
106 if(NULL == linked_list)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
107 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
108 return 0;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
109 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
110
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
111 new_node = LinkedListNode_Create();
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
112 if(NULL == new_node)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
113 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
114 return 0;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
115 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
116
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
117 new_node->dataPtr = new_item;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
118
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
119 if(0 == linked_list->currentSize)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
120 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
121 linked_list->headPtr = new_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
122 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
123 else
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
124 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
125 LinkedListNode* tail_node = linked_list->tailPtr;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
126 new_node->previousNode = tail_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
127 tail_node->nextNode = new_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
128 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
129
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
130 linked_list->tailPtr = new_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
131 linked_list->currentSize++;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
132 return 1;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
133
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
134 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
135
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
136 void* LinkedList_PopFront(LinkedList* linked_list)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
137 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
138 LinkedListNode* head_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
139 void* return_data;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
140
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
141 if(NULL == linked_list)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
142 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
143 return 0;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
144 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
145 if(0 == linked_list->currentSize)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
146 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
147 return NULL;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
148 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
149
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
150 head_node = linked_list->headPtr;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
151 return_data = head_node->dataPtr;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
152
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
153 if(1 == linked_list->currentSize)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
154 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
155 LinkedList_Clear(linked_list);
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
156 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
157 else
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
158 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
159 LinkedListNode* next_node = head_node->nextNode;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
160 next_node->previousNode = NULL;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
161 LinkedListNode_Free(head_node);
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
162 linked_list->headPtr = next_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
163 linked_list->currentSize = linked_list->currentSize - 1;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
164
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
165 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
166 return return_data;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
167 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
168
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
169 void* LinkedList_PopBack(LinkedList* linked_list)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
170 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
171 LinkedListNode* tail_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
172 void* return_data;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
173
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
174 if(NULL == linked_list)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
175 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
176 return NULL;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
177 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
178 if(0 == linked_list->currentSize)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
179 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
180 return NULL;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
181 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
182
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
183 tail_node = linked_list->tailPtr;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
184 return_data = tail_node->dataPtr;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
185
17
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
186 if(1 == linked_list->currentSize)
13
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
187 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
188 LinkedList_Clear(linked_list);
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
189 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
190 else
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
191 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
192 LinkedListNode* previous_node = tail_node->previousNode;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
193 previous_node->nextNode = NULL;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
194 LinkedListNode_Free(tail_node);
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
195 linked_list->tailPtr = previous_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
196 linked_list->currentSize = linked_list->currentSize - 1;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
197 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
198 return return_data;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
199 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
200
17
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
201
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
202 void* LinkedList_Front(LinkedList* linked_list)
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
203 {
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
204 LinkedListNode* head_node;
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
205 void* return_data;
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
206
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
207 if(NULL == linked_list)
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
208 {
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
209 return 0;
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
210 }
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
211 if(0 == linked_list->currentSize)
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
212 {
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
213 return NULL;
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
214 }
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
215
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
216 head_node = linked_list->headPtr;
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
217 return_data = head_node->dataPtr;
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
218
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
219 return return_data;
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
220 }
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
221
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
222 void* LinkedList_Back(LinkedList* linked_list)
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
223 {
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
224 LinkedListNode* tail_node;
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
225 void* return_data;
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
226
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
227 if(NULL == linked_list)
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
228 {
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
229 return NULL;
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
230 }
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
231 if(0 == linked_list->currentSize)
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
232 {
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
233 return NULL;
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
234 }
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
235
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
236 tail_node = linked_list->tailPtr;
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
237 return_data = tail_node->dataPtr;
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
238
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
239 return return_data;
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
240 }
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
241
d58eb38c771b Needed new Front and Back (non-popping) functions for LinkedList.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 15
diff changeset
242
13
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
243 size_t LinkedList_Size(LinkedList* linked_list)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
244 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
245 if(NULL == linked_list)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
246 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
247 return 0;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
248 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
249 return linked_list->currentSize;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
250 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
251
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
252 void LinkedList_Clear(LinkedList* linked_list)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
253 {
21
14c22fc3c753 Fix to LinkedList_Clear
Eric Wing <ewing . public |-at-| gmail . com>
parents: 17
diff changeset
254 LinkedListNode* current_node;
14c22fc3c753 Fix to LinkedList_Clear
Eric Wing <ewing . public |-at-| gmail . com>
parents: 17
diff changeset
255 LinkedListNode* next_node;
13
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
256 if(NULL == linked_list)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
257 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
258 return;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
259 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
260
21
14c22fc3c753 Fix to LinkedList_Clear
Eric Wing <ewing . public |-at-| gmail . com>
parents: 17
diff changeset
261 current_node = linked_list->headPtr;
13
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
262 while(NULL != current_node)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
263 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
264 next_node = current_node->nextNode;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
265 LinkedListNode_Free(current_node);
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
266 current_node = next_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
267 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
268 linked_list->headPtr = NULL;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
269 linked_list->tailPtr = NULL;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
270 linked_list->currentSize = 0;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
271 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
272
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
273 void* LinkedListNode_GetData(LinkedListNode* list_node)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
274 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
275 if(NULL == list_node)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
276 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
277 return NULL;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
278 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
279 return list_node->dataPtr;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
280 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
281
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
282 LinkedListNode* LinkedList_Find(LinkedList* linked_list, void* the_data, LinkedListNode* start_node)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
283 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
284 LinkedListNode* current_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
285 if(NULL == linked_list)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
286 {
15
b27f7ff5e44b Needed return NULL.
Eric Wing <ewing . public |-at-| gmail . com>
parents: 13
diff changeset
287 return NULL;
13
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
288 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
289 if(NULL == start_node)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
290 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
291 start_node = linked_list->headPtr;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
292 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
293
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
294 for(current_node = start_node; NULL != current_node; current_node = current_node->nextNode)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
295 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
296 if(current_node->dataPtr == the_data)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
297 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
298 return current_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
299 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
300 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
301 return current_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
302 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
303
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
304 /* Make sure your LinkedListNode is actually connected to the
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
305 * LinkedList instance you pass.
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
306 */
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
307 unsigned int LinkedList_Remove(LinkedList* linked_list, LinkedListNode* list_node)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
308 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
309 LinkedListNode* previous_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
310 LinkedListNode* next_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
311 if(NULL == linked_list)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
312 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
313 return 0;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
314 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
315 if(NULL == list_node)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
316 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
317 return 0;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
318 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
319
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
320 if(1 == linked_list->currentSize)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
321 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
322 LinkedList_Clear(linked_list);
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
323 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
324 else if(list_node == linked_list->headPtr)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
325 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
326 LinkedList_PopFront(linked_list);
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
327 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
328 else if(list_node == linked_list->tailPtr)
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
329 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
330 LinkedList_PopBack(linked_list);
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
331 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
332 else
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
333 {
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
334 previous_node = list_node->previousNode;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
335 next_node = list_node->nextNode;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
336
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
337 previous_node->nextNode = next_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
338 next_node->previousNode = previous_node;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
339 LinkedListNode_Free(list_node);
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
340
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
341 linked_list->currentSize = linked_list->currentSize - 1;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
342 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
343
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
344 return 1;
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
345
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
346 }
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
347
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
348
54aa96ae8912 Added LinkedList class to project.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
349