c语言帮我看看那里错了..
发布网友
发布时间:2023-12-08 23:58
我来回答
共4个回答
热心网友
时间:2024-07-14 12:29
/*
36 45 70 13 42 67 80 37 81 29
29 81 37 80 67 42 13 70 45 36
Press any key to continue
*/
#include <stdio.h>
#include <stdlib.h>
typedef int datatype;
typedef struct node {
datatype data;
struct node *next;
}StackNode ,*LinkStack;
LinkStack Init_LinkStack() {
LinkStack head = (LinkStack)malloc(sizeof(StackNode));
head->next = NULL;
return head;
}
int Empty_LinkStack(LinkStack head) {
return(head->next == NULL);
}
void Push_LinkStack(LinkStack head, datatype x) {
LinkStack s = (LinkStack)malloc(sizeof(StackNode));
s->data = x;
s->next = head->next;
head->next = s;
}
int Pop_LinkStack(LinkStack head,datatype *x) {
LinkStack p;
if(Empty_LinkStack(head)) return 0;
*x = head->next->data;
p = head->next;
head->next = p->next;
free(p);
return 1;
}
// 返回栈顶元素,成功,x存放栈顶元素,返回1。否则,返回0,x的值不可用
int Get_LinkStackTop(LinkStack head,datatype *x) {
if(Empty_LinkStack(head)) return 0;
*x = head->next->data;
return 1;
}
void Show_LinkStack(LinkStack head) {
LinkStack p = head->next;
while(p) {
printf("%d ",p->data);
p = p->next;
}
printf("\n");
}
void Free_LinkStack(LinkStack head) {
LinkStack p,q;
p = head;
while(p) {
q = p;
p = q->next;
free(q);
}
}
int main() {
LinkStack s = Init_LinkStack();
datatype a[] = {36,45,70,13,42,67,80,37,81,29};
int i,n = sizeof(a)/sizeof(a[0]);
for(i = 0; i < n; ++i) {
printf("%d ",a[i]);
Push_LinkStack(s,a[i]);
}
printf("\n");
Show_LinkStack(s);
Free_LinkStack(s);
return 0;
}
热心网友
时间:2024-07-14 12:29
一开头就多了三个字符了
热心网友
时间:2024-07-14 12:29
没有main函数,具体问题说清楚点
热心网友
时间:2024-07-14 12:30
你这粘贴成这幅摸样,不太好看啊,不如截图?