The programming of the head-inserting method of the chain table to realize __ programming

Source: Internet
Author: User

The idea of head-inserting is to build a head knot, point yourself to yourself, and then come to a new node.

Let the new node point to the node that the head node points to, and then let the head node point to the new node.

In this way, the new node will always be inserted into the end of the knot is the head interpolation method.

C Language Programming implementation

#include <stdio.h>
#include <malloc.h>
struct list {  
    int A;  
    struct list * next;
} ;  
struct list * head;
struct list * P=NULL; 
int main () {
	printf ("%s\n", "Please enter the length of the list)";
	int length=0,i,data;
	scanf ("%d", &length);
	printf ("%s\n", "Enter the data in the list sequentially");
    Head = (struct list *) malloc (sizeof (struct  list));
	head->next=null;
	for (i=0;i<length;i++) {
		p = (struct list *) malloc (sizeof (struct  list));
		scanf ("%d", &p->a);
	    p->next=head->next; 
	    head->next=p; 
	}
	while (p!=null) {
		 printf ("%d  ", p->a);
	     p=p->next;
	}


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.