Setting up single-linked list by head interpolation

Source: Internet
Author: User

#include <stdio.h>
#include <stdlib.h>

typedef struct node{
int data;
struct node *next;
}lnode,*linklist;

linklist creat_list ()
{
linklist head=null;
head= (linklist) malloc (sizeof (Lnode));
if (head==null)
{
printf ("Memory out of use\n");
return NULL;
}
head->next=null;
head->data=0;
return head;
}

int Insert (linklist head,int N)
{
for (int i=0;i<n;i++)
{

Linklist head_t=head->next;
Linklist New_node=null;


new_node= (linklist) malloc (sizeof (Lnode));
if (new_node==null)
{
printf ("Memory out of use\n");
return-1;
}
printf ("Please input the value:\n");
scanf ("%d", &new_node->data);
new_node->next=head_t;
head->next=new_node;
}

return 0;
}
int show_list (linklist head)
{
linklist tem;
tem=head->next;
While (TEM)
{
printf ("%3d", tem->data);
tem=tem->next;
}
return 0;
}

int main ()
{
linklist head;
int n;
printf ("Please input the size which your want to insert\n");
scanf ("%d", &n);
head=creat_list ();
Insert (head,n);
Show_list (head);
return 0;
}

Setting up single-linked list by head interpolation

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.