From cf73dfd8b68dd536bf42c31e06e924c5a6a7aa7c Mon Sep 17 00:00:00 2001 From: penguinc Date: Sun, 25 Sep 2005 20:40:35 +0000 Subject: [PATCH] Fixed a few subtle C errors and programmatic mistakes. --- Linked.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Linked.c b/Linked.c index d84899b..c7ece94 100755 --- a/Linked.c +++ b/Linked.c @@ -101,15 +101,23 @@ Element Pop ( List *mylist ) { data = Return->NodeElement; if ( Return->Previous != NULL ) Return->Previous->Next = Next; - Next->Previous = Return->Previous; - free ( Return ); + if ( Next != NULL ) { + Next->Previous = Return->Previous; + if ( Next->Previous == Next ) + Next->Previous = NULL; + if ( Next->Next == Next ) + Next->Next = NULL; + } + free ( Return ); mylist->size--; } return data; } short Enqueue ( List *mylist, Element Data ) { - return InsertAt ( mylist, Data, mylist->RootNode ); + if ( mylist->RootNode == NULL || mylist->RootNode->NodeElement == NULL ) + return InsertAt ( mylist, Data, mylist->RootNode ); + return InsertAt ( mylist, Data, mylist->RootNode->Previous ); } Element Dequeue ( List *mylist ) { @@ -155,6 +163,8 @@ void MakeEmpty ( List *mylist ) { next = NULL; node = mylist->RootNode; mylist->size = 0; + if ( node == NULL ) + return; if ( node->Previous != NULL ) node->Previous->Next = NULL;