注册 登录
编程论坛 C语言论坛

c语言尾插法建立单链表

Z1020 发布于 2020-09-29 21:16, 1897 次点击
不知道为什么不对,来个大佬救救孩子
程序代码:
//用尾差法建立单链表
#include<stdio.h>
#include<stdlib.h>
typedef int elemType;
typedef struct Linklist{
    elemType data1;
    elemType data2;
    struct Linklist *next;
}node;
int main(){
    node*l;
    InitList(l);
    CreatLinkList(l);
    return 0;
}
int InitList(node *l){//初始化
    l=(node*)malloc(sizeof(node));
    l->next=NULL;
    return 0;
}
//用尾差法建表
int CreatLinkList(node *l){
    elemType a,b;
    node *s,*r;//r指向节点的尾指针
    int flag=1;//输入结束标志
    r=l;
    while(flag)
    {
        scanf("%int%int",&a,&b);
        if(a!=0)
        {
            s=(node*)malloc(sizeof(node));
            s->data1=a;
            s->data2=b;
            r->next=s;
            r=s;//尾指针换位
        }
        else
        {
            flag=0;
            r->next=NULL;
        }
    }
    return 0;
}
3 回复
#2
Z10202020-09-29 21:17
#3
fishxiaoyun2020-09-29 22:27
scanf里的%int是啥意思?
#4
Z10202020-09-29 23:55
回复 3楼 fishxiaoyun
不知道为什么传上来就是这个样子是%d
1