dranowrong 2023-02-23 16:47 采纳率: 60%
浏览 18

C语言之栈帧的链式存储

1.代码编译错误是为啥啊
2.可以的话能把这个栈帧的链式存储结构在此代码的基础上修改一下么


#include <stdio.h>
#include <stdlib.h>
typedef int ElementType

struct Stack {
    ElementType Data;
    struct Stack *Next;
};

struct Stack CreateStack() { //头结点
    struct Stack *S;
    S = (struct Stack *)malloc(sizeof(struct Stack));
    S -> Next = NULL;
    return S;
}

void Push(ElementType item, struct Stack *S) {
    struct Stack *TmpCell;
    TmpCell = (struct Stack *)malloc(sizeof (struct Stack));
    TmpCell -> Element = item;
    TmpCell -> Next = S -> Next;
    S -> Next = TmpCell;
}

//链表不需要判别是否满了
ElementType Pop(struct Stack *S) {
//删除并返回堆栈S的栈顶元素
    struct Stack *FirstCell;
    ElementType TopElem;
    if (IsEmpty(S))  {
        printf("堆栈空");
        return 0;
    } else {
        FirstCell = S-> Next;
        S->Next = FirstCell -> Element;
        free(FirstCell);
        return TopElem;
    }
}

int main() {
    return 0;
}
  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2023-02-23 18:20
    关注
    评论

报告相同问题?

问题事件

  • 创建了问题 2月23日