Data structure and algorithm learning notes (iv)

Source: Internet
Author: User

    1. Full table creation for single-linked lists
      1. Declares a node p and counter variable i
      2. Initialize an empty list L
      3. The pointer to the head node of L points to null, which is a single linked list that creates a lead node
      4. The assignment and insertion of successive nodes in a cyclic implementation
    2. Head interpolation: Starting with an empty table, generating a new node, reading the data into the data field of the new node, and inserting the new node into the table header of the current list until the end position. Simply put the newly added element in the first position after the table header
      1. Let the next point of the new node go to the head node.
      2. Then point the table header next to the new node.
voidCreatelisthead (linklist *l,intN) {linklist p; inti; Srand (Time (0));//Initialize random number seed*l = (linklist)malloc(sizeof(Node)); (*L)->next =NULL;  for(i =0; I < n; i++) {p= (linklist)malloc(sizeof(Node)); P->data = rand ()% -+1; P->next = (*l)Next}}

3. Setting up single-link list by tail interpolation

voidCreatelisttail (linklist *l,intN) {linklist p,r; inti; Srand (Time (0));//Initialize random number seed*l = (linklist)malloc(sizeof(Node)); R= *L;  for(i =0; I < n; i++) {p= (Node *)malloc(sizeof(Node)); P->data = rand ()% -+1; R->next =p; R=p; } R->next =NULL;}

Data structure and algorithm learning notes (iv)

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.