Update stack.c

fix issue #223
This commit is contained in:
Ashwek Swamy 2019-06-08 11:33:27 +05:30 committed by GitHub
parent b1fed3cf3e
commit 8e5f2ea3f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -88,6 +88,7 @@ void push(int x) {
tmp->data = x;
tmp->next = NULL;
tmp->pre = head;
head->next = tmp;
head = tmp;
}
++count;
@ -104,8 +105,10 @@ int pop() {
} else {
returnData = head->data;
if(head->pre == NULL)
if(head->pre == NULL){
free(head);
head = NULL;
}
else {
head = head->pre;
free(head->next);