开云·体育·ios软件官方手机版appv9.65-IOS/安卓最新版
开云体育游戏介绍,开云体育app下载免费安装,开云体育官方网站下载,开云体育官网手机版入口最新网址已发。我的邮箱[email protected]。
C语言建立单链表的程序无法正常运行
错误在create()函数中,修改如下:
struct LNode *create(int n){ int i; struct LNode *p1,*p2,*head; int a; head=NULL; printf("输入整数:\n"); for(i=n;i>0;--i) { p1=(struct LNode*)malloc(sizeof(struct LNode));//注意这里 scanf("%d",&a); p1->data=a; if(head==NULL) head=p1; //注意这里 else p2->next=p1; //注意这里 p2=p1; //注意这里 } p2->next=NULL; return head;}
用C语言实现建立一个单链表的过程,并实现打印链表中每一个元素,写出完整程序
这是个很简单的链表创建和输出
#include
#include
typedef struct linkednode
{
char data;
struct linkednode *next;
}node,*link_list;//链表节点的结构及重命名
link_list creat()//创建一个链表返回类型是链表的首地址
{
link_list L;
node *p1,*p2;
char data;
L=(node*)malloc(sizeof(node));//开辟存储空间
p2=L;
while((data=getchar())!='\n')//输入回车键时结束输入
{
p1=(node*)malloc(sizeof(node));
p1->data=data;
p2->next=p1;
p2=p1;
}
p2->next=NULL;
return L;
}
void print(link_list L)//把链表输出
{
node *p;
p=L->next;
while(p!=NULL)
{
printf("%c",p->data);
p=p->next;
}
printf("\n");
}
void main()
{
link_list L=NULL;
char x;
printf("请输入链表节点:\n");
L=creat();
print(L);
}