Data structure and algorithm learning (III.)

Source: Internet
Author: User

Whole table of single linked list * Create *: The idea is to create an empty table before inserting.

Head Interpolation method:

Void Createlisthead (linklist *l,int N)

{linklist p;

int i;

(*l)->next=null;

Srand (Time (0));//initialization of random numbers

*l= (linklist) malloc (sizeof (Node));

for (i=1;i<=n;i++)

{p= (linklist) malloc (sizeof (Node));

P->data=rand ()%100+1;//rand range is 0-99, note modulo,%100 get two digits +1 range 1-100

p->next= (*l)->next;

(*l)->next=p;

}

}

Tail interpolation method:

Void Createlisttail (linklist *l,int N)

{linklist p,r;//one more R variable

int i;

(*l) = (linklist) malloc (sizeof (Node));

R= (*L);

Srand (Time (0));//initialization of random numbers

for (i=0;i<n;i++)

{p= (linklist) malloc (sizeof (Node));

P->data=rand ()%100+1;

r->next=p;

R=p;}

}

Data structure and algorithm learning (III.)

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.