Creation and destruction of single linked list for C + + learning

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.