annotate LinkedList.h @ 17:d58eb38c771b

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