change next to prev, just makes more sense

This commit is contained in:
Emanuel Rodriguez 2023-06-30 07:46:20 -07:00
parent 30315e6d29
commit 722aecd6dc
1 changed files with 4 additions and 4 deletions

View File

@ -17,7 +17,7 @@ pop: len = 0 /[A]/
typedef struct Node { typedef struct Node {
int value; int value;
struct Node* next; struct Node* prev;
} Node; } Node;
typedef struct Stack { typedef struct Stack {
@ -28,7 +28,7 @@ typedef struct Stack {
Node* new_node(int value) { Node* new_node(int value) {
Node* n = malloc(sizeof(Node)); Node* n = malloc(sizeof(Node));
n->value = value; n->value = value;
n->next = NULL; n->prev = NULL;
return (n); return (n);
} }
@ -47,7 +47,7 @@ bool pop(Stack* s) {
if (s->length == 1) { if (s->length == 1) {
s->head = NULL; s->head = NULL;
} else { } else {
s->head = n->next; s->head = n->prev;
} }
free(n); free(n);
s->length--; s->length--;
@ -67,7 +67,7 @@ void push(Stack* s, Node* n) {
s->length++; s->length++;
} else { } else {
// make the old head point to what will be the new head // make the old head point to what will be the new head
n->next = s->head; n->prev = s->head;
// make the head point to n now // make the head point to n now
s->head = n; s->head = n;
s->length++; s->length++;