Renamed Node to ListNode
* source/server/lists.c (appendToList): String replaced Node with ListNode. (deleteNodeFromList): String replaced Node with ListNode. (deleteListNodeFromList): String replaced Node with ListNode. (indexOfFromList): String replaced Node with ListNode. (getFirstFromList): String replaced Node with ListNode. (isInList): String replaced Node with ListNode. (isPointerInList): String replaced Node with ListNode. * source/server/lists.h: String replaced Node with ListNode.
This commit is contained in:
parent
ef3cfb69c2
commit
80dce61058
|
@ -27,27 +27,27 @@ size_t appendToList(enum DataType type, struct List * list, void * data)
|
|||
// First check that you're adding the correct type:
|
||||
assert(type == list->type);
|
||||
|
||||
struct Node * newNode = calloc(1, sizeof(struct Node));
|
||||
newNode->next = NULL;
|
||||
newNode->previous = list->tail;
|
||||
newNode->data = data;
|
||||
struct ListNode * newListNode = calloc(1, sizeof(struct ListNode));
|
||||
newListNode->next = NULL;
|
||||
newListNode->previous = list->tail;
|
||||
newListNode->data = data;
|
||||
|
||||
if (list->itemCount == 0)
|
||||
{
|
||||
list->head = newNode;
|
||||
list->head = newListNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
list->tail->next = newNode;
|
||||
list->tail->next = newListNode;
|
||||
}
|
||||
|
||||
list->tail = newNode;
|
||||
list->tail = newListNode;
|
||||
list->itemCount++;
|
||||
|
||||
return list->itemCount;
|
||||
}
|
||||
|
||||
void * deleteNodeFromList(size_t index, struct List * list)
|
||||
void * deleteListNodeFromList(size_t index, struct List * list)
|
||||
{
|
||||
void * toReturn;
|
||||
|
||||
|
@ -56,31 +56,31 @@ void * deleteNodeFromList(size_t index, struct List * list)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct Node * currentNode = NULL;
|
||||
struct ListNode * currentListNode = NULL;
|
||||
|
||||
if (index < (list->itemCount / 2))
|
||||
{
|
||||
currentNode = list->head;
|
||||
currentListNode = list->head;
|
||||
|
||||
// Get to the correct point in the linked list:
|
||||
for (int currentIndex = 0; currentIndex < index; currentIndex++)
|
||||
{
|
||||
currentNode = currentNode->next;
|
||||
currentListNode = currentListNode->next;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
currentNode = list->tail;
|
||||
currentListNode = list->tail;
|
||||
|
||||
// Get to the correct point in the linked list:
|
||||
for (int currentIndex = list->itemCount - 1; currentIndex > index; currentIndex--)
|
||||
{
|
||||
currentNode = currentNode->previous;
|
||||
currentListNode = currentListNode->previous;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentNode == list->head)
|
||||
if (currentListNode == list->head)
|
||||
{
|
||||
list->head = list->head->next;
|
||||
if (list->head)
|
||||
|
@ -88,7 +88,7 @@ void * deleteNodeFromList(size_t index, struct List * list)
|
|||
list->head->previous = NULL;
|
||||
}
|
||||
}
|
||||
if (currentNode == list->tail)
|
||||
if (currentListNode == list->tail)
|
||||
{
|
||||
list->tail = list->tail->previous;
|
||||
if (list->tail)
|
||||
|
@ -97,18 +97,18 @@ void * deleteNodeFromList(size_t index, struct List * list)
|
|||
}
|
||||
}
|
||||
|
||||
if (currentNode->next != NULL)
|
||||
if (currentListNode->next != NULL)
|
||||
{
|
||||
currentNode->next->previous = currentNode->previous;
|
||||
currentListNode->next->previous = currentListNode->previous;
|
||||
}
|
||||
|
||||
if (currentNode->previous != NULL)
|
||||
if (currentListNode->previous != NULL)
|
||||
{
|
||||
currentNode->previous->next = currentNode->next;
|
||||
currentListNode->previous->next = currentListNode->next;
|
||||
}
|
||||
|
||||
toReturn = currentNode->data;
|
||||
free(currentNode);
|
||||
toReturn = currentListNode->data;
|
||||
free(currentListNode);
|
||||
|
||||
list->itemCount--;
|
||||
|
||||
|
@ -124,17 +124,17 @@ ssize_t indexOfFromList(bool (*comparisonFunction)(void *, void *), void * data,
|
|||
}
|
||||
else
|
||||
{
|
||||
struct Node * currentNode = list->head;
|
||||
struct ListNode * currentListNode = list->head;
|
||||
do
|
||||
{
|
||||
if (comparisonFunction(currentNode->data, data) == true)
|
||||
if (comparisonFunction(currentListNode->data, data) == true)
|
||||
{
|
||||
return index;
|
||||
}
|
||||
index++;
|
||||
currentNode = currentNode->next;
|
||||
currentListNode = currentListNode->next;
|
||||
}
|
||||
while (currentNode != NULL);
|
||||
while (currentListNode != NULL);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -149,17 +149,17 @@ void * getFirstFromList(bool (*comparisonFunction)(void *, void *), void * data,
|
|||
}
|
||||
else
|
||||
{
|
||||
struct Node * currentNode = list->head;
|
||||
struct ListNode * currentListNode = list->head;
|
||||
do
|
||||
{
|
||||
if (comparisonFunction(currentNode->data, data) == true)
|
||||
if (comparisonFunction(currentListNode->data, data) == true)
|
||||
{
|
||||
return currentNode;
|
||||
return currentListNode;
|
||||
}
|
||||
index++;
|
||||
currentNode = currentNode->next;
|
||||
currentListNode = currentListNode->next;
|
||||
}
|
||||
while (currentNode != NULL);
|
||||
while (currentListNode != NULL);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -173,16 +173,16 @@ bool isInList(bool (*comparisonFunction)(void *, void *), void * data, struct Li
|
|||
}
|
||||
else
|
||||
{
|
||||
struct Node * currentNode = list->head;
|
||||
struct ListNode * currentListNode = list->head;
|
||||
do
|
||||
{
|
||||
if (comparisonFunction(currentNode->data, data) == 0)
|
||||
if (comparisonFunction(currentListNode->data, data) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
currentNode = currentNode->next;
|
||||
currentListNode = currentListNode->next;
|
||||
}
|
||||
while (currentNode != NULL);
|
||||
while (currentListNode != NULL);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -196,16 +196,16 @@ bool isPointerInList(void * data, struct List * list)
|
|||
}
|
||||
else
|
||||
{
|
||||
struct Node * currentNode = list->head;
|
||||
struct ListNode * currentListNode = list->head;
|
||||
do
|
||||
{
|
||||
if (currentNode->data == data)
|
||||
if (currentListNode->data == data)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
currentNode = currentNode->next;
|
||||
currentListNode = currentListNode->next;
|
||||
}
|
||||
while (currentNode != NULL);
|
||||
while (currentListNode != NULL);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -12,14 +12,14 @@ struct List
|
|||
{
|
||||
size_t itemCount;
|
||||
enum DataType type;
|
||||
struct Node * head;
|
||||
struct Node * tail;
|
||||
struct ListNode * head;
|
||||
struct ListNode * tail;
|
||||
};
|
||||
|
||||
struct Node
|
||||
struct ListNode
|
||||
{
|
||||
struct Node * next;
|
||||
struct Node * previous;
|
||||
struct ListNode * next;
|
||||
struct ListNode * previous;
|
||||
void * data;
|
||||
};
|
||||
|
||||
|
@ -29,7 +29,7 @@ struct Node
|
|||
|
||||
struct List * createList(enum DataType type);
|
||||
size_t appendToList(enum DataType type, struct List * list, void * data);
|
||||
void * deleteNodeFromList(size_t index, struct List * list);
|
||||
void * deleteListNodeFromList(size_t index, struct List * list);
|
||||
ssize_t indexOfFromList(bool (*comparisonFunction)(void *, void *), void * data, struct List * list);
|
||||
void * getFirstFromList(bool (*comparisonFunction)(void *, void *), void * data, struct List * list);
|
||||
bool isInList(bool (*comparisonFunction)(void *, void *), void * data, struct List * list);
|
||||
|
|
Loading…
Reference in New Issue