Fixed a few subtle C errors and programmatic mistakes.
parent
d3c1479ba1
commit
cf73dfd8b6
16
Linked.c
16
Linked.c
|
@ -101,15 +101,23 @@ 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;
|
||||||
Next->Previous = Return->Previous;
|
if ( Next != NULL ) {
|
||||||
free ( Return );
|
Next->Previous = Return->Previous;
|
||||||
|
if ( Next->Previous == Next )
|
||||||
|
Next->Previous = NULL;
|
||||||
|
if ( Next->Next == Next )
|
||||||
|
Next->Next = NULL;
|
||||||
|
}
|
||||||
|
free ( Return );
|
||||||
mylist->size--;
|
mylist->size--;
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
short Enqueue ( List *mylist, Element 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 ) {
|
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;
|
||||||
|
|
||||||
|
|
Reference in New Issue