Ho il seguente cod:
Ma pero remove nn mi fa il lavoro giusto, help mecodice:#include <iostream> #include <cstdio> using namespace std; struct List { /* * The list information */ int info; /* * The next list element */ List *next; /* * Create struct * 1. The struct info * 2. The next structure addres */ List(int Info, List *Next) { info = Info; next = Next; } /* * Add a element * 1. A List pointer * 2. A value of element */ void add(List *pr, int n) { if(pr == NULL){ /* first element */ pr->info = n; pr->next = NULL; } /* another case */ List *p = pr; while(p->next != NULL) p = p->next; p->next = new List(n, NULL); } /* * Print all element * 1. A List pointer */ void print(List *pr) { List *p = pr; while(p->next != NULL){ cout << "Info = " << p->info <<"\n"; p = p->next; } } /* * Find a element * 1. A List pointer * 2. A index that you wont to find */ List *find(List *pr, int index) { List *p = pr; while((p->next != NULL) && (p->info != index)) p = p->next; return p; } void remove(List* pr, int n) { /* List *p = ls; while((p->next != NULL) && (p->info != n)) p = p->next; delete p; */ } /* * Generate a list based. * 1. a int array * 2. a array lenght */ List* generate(List *pr, int parms[], int lenght) { for(register int i=0;i<lenght;i++){ pr->next = new List(parms[i], NULL); } } }; int main() { List *p = new List(0, NULL); int i = 0; while( i != 10){ p->add(p, i); i++; } p->print(p); p->remove(p, 5); p->print(p); system("PAUSE"); return 0; }![]()
P.s: nomenclatura generale(var e funz) e inglese(commenti) vanno bene???

Rispondi quotando