Nonsense not much to say, directly on the code.
1#include <iostream>2#include <cstdlib>3 4 using namespacestd;5 6typedefintElemtype;7 8 structNode9 {Ten elemtype data; Onenode*Next; A }; - -typedef node*linklist; the - voidInput (elemtype*a) - { -cout<<"Please enter the date value of the current node:"; +CIN >> *A; - } + A //I feel more in line with my habits. at voidCreatelinklist (linklist* L,intNvoidInput (elemtype*)) - { -cout<<"This is the tail-insert-proach ..."<<Endl; - linklist S; -*l =NewNode; -linklist p = *L; in(*l)->next =NULL; - for(;n>0; n--) to { +s =NewNode; -Input (&s->data); theS->next =NULL; *P->next =s; $p =s;Panax Notoginseng } -S->next =NULL; the } + A voidDestorylist (linklist *L) the { +cout<<"We are going to delete the linklist ..."<<Endl; -linklist q,p = *L; $ while(P! =NULL) $ { -Q = p->Next; - Deletep; thep =Q; - }Wuyi the*l =NULL; -cout<<"we have destoryed the linklist ..."<<Endl; Wu } - About intMain () $ { -Linklist L;//The head pointer, which points to the created head node. The data of the head node is null, and next of the tail node is null - intN; -cout<<"Please enter the number of needed nodes (except the head node) ..."<<Endl; ACin>>N; +Createlinklist (&l,n,input); theDestorylist (&L); - return 0; $}
Creation and destruction of single linked list for C + + learning