#include <stdio.h>
#include <malloc.h>
#include <string.h>
typedef struct node{
int data;
struct node *next;
}Node;
void creatt(Node *head, int n)
{
int k=0;
for(int i=0;i<n;i++)
{
Node *b=(Node *)malloc(sizeof(Node));
b->next=head->next;
head->next=b;
//scanf("%d",&k);
b->data=k++;
}
}
void printt(Node *head)
{
Node *p;
p=head->next;
while(p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
}
int main(){
Node * head=(Node *)malloc(sizeof(Node));
head->next=NULL;
creatt(head, 5);
printt(head);
}
//注意:当时写这个程序的时候遇到了一个运行时错误,后来才发现是自己平时学语言太粗心了。注意事项在C\C++中的空指针错误中。
链表的建立
最新推荐文章于 2023-03-26 22:28:36 发布