C语言链表程序,写完后运行不了怎么办,编译的时候没有问题。
#include<stdio.h>#include<stdlib.h>intmain(){typedefstructnode{intdata;structnode*nex...
#include <stdio.h>
#include <stdlib.h>
int main()
{typedef struct node
{int data;
struct node*next;
}node;
node**top;
(*top)=NULL;
int i;
int j;
int x;
printf ("链表中元素个数是:");
scanf ("%d",&i);
printf("元素内容:");
for(j=0;j<i;j++)
{node*p;
p=(node*)malloc(sizeof(node));
scanf("%d",&x);
p->data=x;
p->next=(*top);
(*top)=p;
}
int y;
int z;
for(y=0;y<i;y++)
{z=(*top)->data;
printf("%d",&z);
(*top)=(*top)->next;
}
return 0;
} 展开
#include <stdlib.h>
int main()
{typedef struct node
{int data;
struct node*next;
}node;
node**top;
(*top)=NULL;
int i;
int j;
int x;
printf ("链表中元素个数是:");
scanf ("%d",&i);
printf("元素内容:");
for(j=0;j<i;j++)
{node*p;
p=(node*)malloc(sizeof(node));
scanf("%d",&x);
p->data=x;
p->next=(*top);
(*top)=p;
}
int y;
int z;
for(y=0;y<i;y++)
{z=(*top)->data;
printf("%d",&z);
(*top)=(*top)->next;
}
return 0;
} 展开
展开全部
#include <stdio.h>
#include <stdlib.h>
int main() {
typedef struct node {
int data;
struct node *next;
}node;
int i,n;
node *p,*top;
top = (node *)malloc(sizeof(node)); // 需要申请空间
top->data = 0;
top->next = NULL;
printf ("链表中元素个数是:");
scanf ("%d",&n);
printf("元素内容:\n");
for(i = 0; i < n; ++i) {
p = (node *)malloc(sizeof(node));
scanf("%d",&p->data);
p->next = top->next;
top->next = p;
}
p = top->next;
while(p) {
printf("%d ",p->data);
p = p->next;
}
printf("\n");
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询