c++ - Stack.Pop() using LinkedList -
just know homework problem , have spent hours trying figure little thing out. pop()
won't work. current code pop()
:
stackelement stack::pop(){ position temp; temp = stack.currententry(); stack.delete(); homecoming temp;}
i using delete()
linked list based delete()
function goes this:
void linkedlist::delete(){ if (current == first && atend()){ // remove memory allocation element's info delete ¤t->data; // reset values of linked list original (null) state current = null; pred = null; first = null; } else // checks if current element first node in lists if (current == first){ // create new first element next element first = current->next; // remove memory allocation element's info delete ¤t->data; // new current entry successor of deleted node. current = first; } // when element you're deleting not first node in list else{ assert(!empty()); // temporary node prevent current beingness marroned node *tempnode = current->next; pred->next = tempnode; // remove memory allocation element's info delete ¤t->data; current = tempnode; } }
when compile, throws me error right here:
unhandled exception @ 0x003e5f79 in program5_test.exe: 0xc0000005: access violation writing location 0xf495ee12.
any help appreciated.
you didn't show currententry, bet returns pointer instead of making total copy. delete original leaving pointer pointing @ nothing. crashes when utilize pointer returned pop.
c++ linked-list stack pop
No comments:
Post a Comment