Single linked list of data structures (C + + implementation)

Source: Internet
Author: User

For some time did not write some about the data structure of the program, just the introduction of the algorithm of the course to learn red and black trees, the sense of data structures are almost forgotten, but also to test, and then take to review.

One, C + + implementation of single-linked list

#include <iostream>using namespaceStd;typedefstructlnode{intdata; structLnode *Next;} Lnode,*linklist;voidcreatelist_l (linklist &l,intN{L=NewLnode (); L->next =NULL; Linklist Temp=L;  for(inti = n; i >0; --i) {linklist P=NewLnode (); CIN>> p->data; P->next = temp->Next; Temp->next =p; Temp=p; }}voidprintlist_l (linklist &l,intN) {linklist P= l->Next;  for(inti =0; I < n; ++i) {cout<< p->data<<Endl;; P= p->Next; }}intMain () {linklist testlnode; intLength =Ten;    createlist_l (testlnode,length); printlist_l (testlnode, length);}

This is relatively simple, do not repeat. Follow-up will be added to various data structures.

Single linked list of data structures (C + + implementation)

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.