大家有知道怎么做吗?

数据结构要求:
使用栈结构。
问题描述:
任意输入序列为三个整数,请定义堆栈,并合理安排入栈与出栈的函数调用顺序与次数,使得出栈序列为第二个数字,第一个数
字,第三个数字。
格式提醒:
输入格式:输入的三个整数,注意用空格隔开,最后回车。
忙吧航日两士输出三个整数,注意空格隔开,最后一个数字后面也有空格,之后回车。

供参考:

#include<stdio.h>
#include<stdlib.h>

struct Node
{
    int data;
    struct Node *link;
};

struct Node *top = NULL;

void Push(int n)
{
    struct Node *temp = (struct Node*)malloc(sizeof(struct Node));
    temp->data = n;
    temp->link = top;
    top = temp;
}
void Pop(int *n)
{
    struct Node* temp;
    if(top == NULL) return;
    temp = top;
    *n = temp->data;
    top = top->link;
    free(temp);
}
int main(void)
{
    int x, i;
    scanf("%d", &x);
    Push(x);
    scanf("%d", &x);
    Push(x);
    Pop(&i);
    printf("%d ", i);
    Pop(&i);
    printf("%d ", i);
    scanf("%d", &x);
    Push(x);
    Pop(&i);
    printf("%d \n", i);

    return 0;
}

以下是使用栈结构实现的C++代码:

#include <iostream>
#include <stack>
using namespace std;

int main() {
    int a, b, c;
    stack<int> s;
    cin >> a >> b >> c;
    s.push(a);
    s.push(b);
    s.push(c);
    cout << s.top() << " ";
    s.pop();
    cout << s.top() << " ";
    s.pop();
    cout << s.top() << " ";
    s.pop();
    cout << endl;
    return 0;
}

输入三个整数后,我们将它们依次压入栈中。然后,我们按照出栈序列的要求,依次弹出栈顶元素并输出。最后记得换行。