永发信息网

数据结构的一些问题

答案:1  悬赏:20  手机版
解决时间 2021-04-27 15:58
  • 提问者网友:难遇难求
  • 2021-04-27 04:49
用总是在表的头部插入整数节点的方法建立一个单链表,当输入0时,建表过程结束。
最佳答案
  • 五星知识达人网友:纵马山川剑自提
  • 2021-04-27 05:08

#include "Stdio.h"
#include "Conio.h"
typedef struct node{
int data;
struct node *next;
} Node;
Node * listCreate()
{
Node * head=NULL;
Node *p;
int num;
printf("input the list num:");
scanf("%d",&num);
while(num)
{
p=(Node *) malloc(sizeof(Node));
p->next=NULL;
p->data=num;
if(head!=NULL)
p->next=head;
head=p;
printf("input the list num:");
scanf("%d",&num);
}
return head;
}


int main(void)
{

Node *A ;
A=listCreate();
while(A)
{
printf("-%d",A->data);
A=A->next;
}
getch();
return 0;
}

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯