我想创建一个链表,可以自定义长度,用来存数字并且可以打印,没报错但是卡住了
#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{
struct Node* next;
int date;
}List,*Listp;
void Insert_Node(Listp head,int num)
{
int value,count=1;
for(int i=0;i<num;i++)
{
printf("Input data for node %d : ",count++);
scanf("%d",&value);
Listp up=(Listp)malloc(sizeof(List));
up->date=value;
printf("1");
up->next=head->next;
printf("2");
head->next=up;
}
}
void Inite_List(Listp head)
{
head=(Listp)malloc(sizeof(List));
head->date=0;
head->next=NULL;
}
void Printf_list(Listp head)
{
Listp p=head->next;
int count=1;
printf("Data entered in the list are : \n");
if(p!=NULL)
{
printf("Data : %d",count++,p->date);
p=p->next;
}
}
void main()
{
int num;
Listp head=NULL;
printf("Input the number of nodes : ");
scanf("%d",&num);
Inite_List(head);
Insert_Node(head,num);
Printf_list(head);
}