Single-chain table initialization and creation (tail insertion)

Source: Internet
Author: User
1 # include <stdlib. h> 2 # include <stdio. h> 3 typedef struct node 4 {5 Int data; 6 struct node * Next; 7} node, * linklist; 8 9 void initlist (linklist * l) 10 {11 (* L) = NULL; 12 printf ("initialization successful \ n"); 13} 14 15 linklist creatlist (int n) 16 {17 linklist L, H, s; // L is the tail pointer, H is the head pointer, S is the work pointer 18 int I = 0; 19 if (H = (linklist) malloc (sizeof (node) = NULL) 20 {21 printf ("no space available! "); 22 exit (0); 23} 24 h-> DATA = 0; 25 h-> next = NULL; 26 L = H; 27 for (; I <N; I ++) 28 {29 If (S = (linklist) malloc (sizeof (node) = NULL) 30 {31 printf ("no space can be allocated! "); 32 exit (0); 33} // create a node 34 L-> next = s; // link with the end node 35 printf ("Enter the % d Number", I + 1); 36 scanf ("% d ", & (S-> data); // input data 37 S-> next = NULL; // null 38 L = s; // remove the tail pointer 39 40} 41 return h; 42} 43 44 int main () 45 {46 linklist listlist = NULL; 47 initlist (& listlist ); 48 listlist = creatlist (5); 49 return 0; 50}

During creation, 34-38 rows, links, data input, left blank, tail pointer backward shifting, variable sequence, and post-shifting must be placed behind the link

Related Article

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.