c语言中链表建立与处理中的问题

发布于 2022-09-02 14:08:47 字数 3794 浏览 20 评论 0

#include <stdio.h>
#include <malloc.h>
LL* creat();
LL* sort(LL *);
void print(LL *);
void main ()
{

    typedef struct Linklist
    {
        struct Linklist * pri=NULL;
        struct Linklist * next=NULL;
        int number;
    }LL;

    print(sort(creat()));
}

LL* creat()
{    
    while (1)

    {
       LL *new_one=NULL;
       LL *head=NULL;
       LL *p1=NULL;
        int tem=0;
        printf("请输入数值");
        scanf("%d",&tem);
        if(tem<0)
            return head;
        //建立链表中。。。。。
        int n=0;
        new_one =(LL *)malloc(sizeof(LL));
        //对节点建立关系
        if(p1)
        {
            p1->next=new_one;
            new_one->pri=p1;
        }
        P1=new_one;//保存上一个链表
        if(n=1)
        {
            head=new_one;
        }
        new_one->number=tem;

        
    }


}
LL* sort(LL *head)
{   
    int t;
    t=0;
    LL *p;
    if(head=NULL)
        printf("出错,请首先建立链表");
    //从小到大采用冒泡排序法
   for(    p=head;*p.next;p=*p.next)
       for(    p=head;*p.next;p=*p.next)
       {
    
        
           if(*p.number>*(*p.next).number)
        
           {
        
               t=*p.number;
               *p.number=*(*p.next).number;
               *(*p.next).number=t
           }
    
       }
       return head;

}
void print(LL *p)
{
    printf("从小到大输出");
    while(*p.next)
    {
        printf("d%",*p.number);
        p=*p.next;
    }
    printf("从大到小输出");
    while(*p.pri)
    {
        printf("%d",*p.number);
        p=*p.pri;
    }

}

以上是代码,错误是:
C:UsersJDesktoptext_2.c(3) : error C2143: syntax error : missing '{' before '*'
C:UsersJDesktoptext_2.c(4) : error C2143: syntax error : missing '{' before '*'
C:UsersJDesktoptext_2.c(4) : error C2143: syntax error : missing ')' before '*'
C:UsersJDesktoptext_2.c(4) : error C2143: syntax error : missing '{' before '*'
C:UsersJDesktoptext_2.c(4) : error C2059: syntax error : ')'
C:UsersJDesktoptext_2.c(4) : error C2059: syntax error : ';'
C:UsersJDesktoptext_2.c(5) : error C2143: syntax error : missing ')' before '*'
C:UsersJDesktoptext_2.c(5) : error C2143: syntax error : missing '{' before '*'
C:UsersJDesktoptext_2.c(5) : error C2059: syntax error : ')'
C:UsersJDesktoptext_2.c(5) : error C2059: syntax error : ';'
C:UsersJDesktoptext_2.c(11) : error C2143: syntax error : missing ';' before '='
C:UsersJDesktoptext_2.c(11) : error C2059: syntax error : '='
C:UsersJDesktoptext_2.c(16) : error C2143: syntax error : missing ')' before '('
C:UsersJDesktoptext_2.c(16) : error C2143: syntax error : missing ')' before '('
C:UsersJDesktoptext_2.c(16) : error C2091: function returns function
C:UsersJDesktoptext_2.c(16) : error C2091: function returns function
C:UsersJDesktoptext_2.c(16) : error C2059: syntax error : ')'
C:UsersJDesktoptext_2.c(16) : error C2059: syntax error : ')'
C:UsersJDesktoptext_2.c(17) : error C2059: syntax error : '}'
C:UsersJDesktoptext_2.c(53) : error C2143: syntax error : missing '{' before '*'
C:UsersJDesktoptext_2.c(53) : error C2143: syntax error : missing ')' before '*'
C:UsersJDesktoptext_2.c(53) : error C2143: syntax error : missing '{' before '*'
C:UsersJDesktoptext_2.c(53) : error C2059: syntax error : ')'
C:UsersJDesktoptext_2.c(54) : error C2054: expected '(' to follow 'head'
C:UsersJDesktoptext_2.c(79) : error C2143: syntax error : missing ')' before '*'
C:UsersJDesktoptext_2.c(79) : error C2143: syntax error : missing '{' before '*'
C:UsersJDesktoptext_2.c(79) : error C2059: syntax error : ')'
C:UsersJDesktoptext_2.c(80) : error C2054: expected '(' to follow 'p'
执行 cl.exe 时出错.

text_2.exe - 1 error(s), 0 warning(s)
编译器:vc++6.0
目的:建立一个链表,输入负数结束,实现升序和降序输出

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文