Linked List implementation for a stack
问题 Here is my implemetation of stack with linkedlist STACK using linked list STACK-EMPTY: if L.head == NIL return True else return False PUSH(x): x.next = L.head if L.head != NIL L.head.prev = x L.head = x x.prev = NIL POP(): x = L.head L.head = x.next x.next.prev = L.head return x would you validate this? how to improve ? thanks 回答1: You can improvement the consistency of your data structure: The prev of the list head is always NIL An element which is not in the list has next and prev set to