c++ - Deleting from list -
c++ - Deleting from list -
im having list this:
struct list { int i; int n = 0; list *previous; list *next; list * head = null; list * tail = null; }; im adding elements list , illustration have list { 10000, 10, 200 }. creating fine.
my erase function this:
list * erase(list * lista, list * elem) { list * pom; if(elem != null) { pom = elem->next; elem->next = pom->next; } else { pom = lista; lista = lista->next; } lista->n--; delete pom; } now when want delete item (exactly item, others it's working fine):
erase(l1, l1->head->next->next); i want show result function:
void showsequence(list * m) { for(int = 0; < m->n; i++) { printf("%i ", m->head->i); m->head = m->head->next; } } and result need phone call showsequence twice because first time gives me {0, 10} , sec (fine) {200, 10}.
any ideas why?
your showsequence function modifies head link. on sec call, m->head @ lastly link.
void showsequence(list * m) { list *c = m->head; for(int = 0; < m->n; i++) { printf("%i ", c->i); c = c->next; } } c++ algorithm list
Comments
Post a Comment