java - 数据结构 c语言 作用域问题

 大众化的公爵樱桃rwr_208 发布于 2022-10-27 21:01

问题用//标出来了,同样的语句为什么放入循环结果就完全不同了?

#include 
#include 
#define OK 1
#define NO 0
int nn=0;
typedef struct Node
{
    int data;
    struct Node *next;
}Node,*Linkstackptr;
typedef struct
{
    Linkstackptr top;
    int count;
}Linkstack;

Linkstackptr Createstacktail(Linkstack *S,int n)   
{
    Linkstackptr r,p;
    S->count=0;

    Linkstackptr *L;
    *L=(Node*)malloc(sizeof(Node));
    (*L)->data=++nn;(*L)->next=NULL;
    r=*L;
    S->top=*L; S->count++;
    printf("%d\n",(*L)->data);          //
    int j;
    for(j=1;jdata);       //
        p=(Node*)malloc(sizeof(Node));
        p->data=++nn;
        p->next=NULL;
        r->next=p;
        r=p;
        S->count++;
    }
    //printf("%d\n",(*L)->data);
    //printf("%d\n",(*L)->next);
    return *L;
}

//bool push()
void Showlist(Linkstackptr L)
{
    while(L)
    {
        printf("%d\n",L->data);
        L=L->next;
    }
}
void main()
{
    Linkstackptr first;
    Linkstack S;
    first=Createstacktail(&S,3);
    //Showlist(first);
    //printf("%d\n",S.count);

    //Showlist(first);
}
2 个回答
  • 在学数据结构 可以去学堂在线上课,选择这堂课的资料学习,丢掉你现在手上的书,这代码风格,现代编译器一堆报错

    2022-10-29 03:53 回答
  • Code style 挺醉人的……

    还是赶紧扔掉谭浩强吧

    $ gcc linkstack.c -o link && ./link
    [1]    6174 segmentation fault  ./link
    
    $ gcc --version
    gcc (Ubuntu 5.4.1-2ubuntu1~16.04) 5.4.1 20160904
    Copyright (C) 2015 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    2022-10-29 03:54 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有