题解 | #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;
}

全部评论

相关推荐

牛客37185681...:马德,我感觉这是我面过最恶心的公司,一面是两个女hr,说什么实习前几个月属于试用期,试用期过了才能转成正式实习生,我***笑了,问待遇就是不说,问能不能接受全栈,沙币公司
如果可以选,你最想去哪家...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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