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,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;