The names chosen readily collide (like top) with existing code and do no indicate their common origin. What I would do to fix it is in your add method, check the size of your list if its 0, set the head to the new element and set the tail equal to the head. Avail is a pointer to the top element of the availability stack SAVE is a temporary pointer variable. Return -111 //assuming it -111 won't be in the stackįor(Node* trav = s->head trav != NULL trav = trav->next)Ĭode such as this is not used in isolation, but with other code. In linked list implementation, a stack is a pointer to the head of the list where pushing and popping items happens, with perhaps a counter to keep track. typical node contains INFO and LINK fields. The code is tested and works however, I am interested in any improvement ideas. Remove the first node from the list by setting items items. Derek Elkins left SE at 6:49 Yes you could remove that abstraction. At this level, the only thing the 'head of a list' could possibly be is an element. At the level of the abstract data type, there are no 'nodes'. I have implemented my stack based on a doubly linked list. A linked list is a basic data structure where each item contains the information that we need to get to the next item. Linked-list Implementation Check whether the stack is empty if so, throw an EmptyStackException. A linked list is an implementation of an abstract data type.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |