问题用//标出来了,同样的语句为什么放入循环结果就完全不同了?#include <stdio.h>#include <stdlib.h>#define OK 1#define NO 0int 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;j<n;j++) { printf("%d\n",(*L)->data); // 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;}void main(){ Linkstackptr first; Linkstack S; first=Createstacktail(&S,3); //Showlist(first); //printf("%d\n",S.count); //Showlist(first);}
1 回答
临摹微笑
TA贡献1982条经验 获得超2个赞
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.
添加回答
举报
0/150
提交
取消