题解 | #complexityTransposition#

Zero-complexity Transposition

https://www.nowcoder.com/practice/c54775799f634c72b447ef31eb36e975

#include <stdio.h>
#include <stdbool.h>
#define MAXSIZE 1000
typedef int ElemType;
typedef struct {
    ElemType data[MAXSIZE];
    int top;
} Stack;
// 初始化一个栈:
void InitStack(Stack *S) {
    S->top = -1;
}
// 栈判空:
bool StackEmpty(Stack S) {
    if (S.top == -1) {
        return true;
    } else
        return false;
}
// 进栈:
bool Push(Stack *S, ElemType x) {
    if (S->top == MAXSIZE - 1)
        return false;
    else {
        S->data[++S->top] = x;
        return true;
    }
}
// 出栈:
bool Pop(Stack *S, ElemType *x) {
    if (S->top != -1) {
        *x = S->data[S->top--];
        return true;
    } else
        return false;
}
// 读取栈顶元素:
bool GetTop(Stack S, ElemType *x) {
    if (S.top == -1)
        return false;
    else {
        *x = S.data[S.top];
        return true;
    }
}
int main() {
    int n;
    scanf("%d", &n);
    Stack S;
    InitStack(&S);
    int number;
    int Arr[n];
    while (n--) {
        scanf("%d", &number);
        Push(&S, number);
    }
    int i = 0;
    while (S.top != -1) {
        Pop(&S, &number);
        printf("%d ", number);
    }
    printf("\n");
    return 0;
}

全部评论

相关推荐

昨天 11:16
湖南大学 Web前端
我看到好多人都在说0offer好焦虑,结果一看是投了百度快手字节啥的。好像大家都是只想通过校招进大厂,对小公司是不考虑的吗😂可是能进大厂的难道不是只有少部分人吗,真心发问
梦想是成为七海千秋:沉默的大多数吧,喜欢晒的都是能引起共鸣的大厂,找小厂的人,别人也不认识你这个小厂,就自己偷偷找了实际上大多数人哪有什么机会能找到大厂
点赞 评论 收藏
分享
我就是0offer糕手:北大不乱杀
点赞 评论 收藏
分享
每晚夜里独自颤抖:你cet6就cet6,cet4就cet4,你写个cet证书等是什么意思。专业技能快赶上项目行数,你做的这2个项目哪里能提现你有这么多技能呢
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务