Código
class Link{ struct node{ node *next; int vl; }; node *head; node *curr; node *temp; public: Link(){ head = curr = temp = NULL; } void Add(int d){ node *n = new node; n-> next = NULL; n->vl = d; if( head == NULL) { head = n; } else { curr = head ; while(curr->next){ curr = curr->next; } curr->next = n; curr = n; } } void Delete(int vl){ temp = head; curr = head; node *temp_; if(head != NULL){ if( head->vl == vl ) { if(head->next != NULL) { temp = head->next; temp_ = head; head = temp; delete temp_; temp_ = NULL; return; } } } while(curr != NULL && curr->vl != vl){ temp = curr; curr = curr->next; } if(curr == NULL) return; else{ temp_ = curr; curr = curr->next; temp->next = curr; delete temp_; temp_ = NULL; } } void Print(){ node *temp = head; if(temp != NULL){ while(temp != NULL) { cout << temp->vl <<endl; temp = temp->next; } } } }; int main(){ Link li; li.Add(0); li.Add(1); li.Add(2); li.Add(3); li.Add(4); li.Add(5); li.Add(6); li.Add(7); li.Add(8); li.Add(9); li.Delete(5); li.Delete(0); li.Delete(8); li.Print(); }
me gustaria opiniones. gracias de antemano...