Fixed a few subtle C errors and programmatic mistakes.

master
penguinc 2005-09-25 20:40:35 +00:00
parent d3c1479ba1
commit cf73dfd8b6
1 changed files with 13 additions and 3 deletions

View File

@ -101,7 +101,13 @@ Element Pop ( List *mylist ) {
data = Return->NodeElement; data = Return->NodeElement;
if ( Return->Previous != NULL ) if ( Return->Previous != NULL )
Return->Previous->Next = Next; Return->Previous->Next = Next;
if ( Next != NULL ) {
Next->Previous = Return->Previous; Next->Previous = Return->Previous;
if ( Next->Previous == Next )
Next->Previous = NULL;
if ( Next->Next == Next )
Next->Next = NULL;
}
free ( Return ); free ( Return );
mylist->size--; mylist->size--;
} }
@ -109,7 +115,9 @@ Element Pop ( List *mylist ) {
} }
short Enqueue ( List *mylist, Element Data ) { short Enqueue ( List *mylist, Element Data ) {
if ( mylist->RootNode == NULL || mylist->RootNode->NodeElement == NULL )
return InsertAt ( mylist, Data, mylist->RootNode ); return InsertAt ( mylist, Data, mylist->RootNode );
return InsertAt ( mylist, Data, mylist->RootNode->Previous );
} }
Element Dequeue ( List *mylist ) { Element Dequeue ( List *mylist ) {
@ -155,6 +163,8 @@ void MakeEmpty ( List *mylist ) {
next = NULL; next = NULL;
node = mylist->RootNode; node = mylist->RootNode;
mylist->size = 0; mylist->size = 0;
if ( node == NULL )
return;
if ( node->Previous != NULL ) if ( node->Previous != NULL )
node->Previous->Next = NULL; node->Previous->Next = NULL;