#include <iostream>
using namespace std;
#define MAX 100
typedef struct Node
{
int data;
int min;
}Node, *pNode;
int minimum = 65535;
int index = -1;
void push(Node* S, int data)
{
S[++index].data = data;
minimum = minimum > data ? data : minimum;
S[index].min = minimum;
}
pNode pop(Node* S)
{
if (index < 0)
{
cout<<"bomb~"<<endl;
return NULL;
}
return &S[index--];
}
int minInS(Node* S)
{
pNode x = pop(S);
push(S, x->data);
return x->min;
}
int main(void)
{
Node Stack[MAX];
push(Stack, 1);
push(Stack, 2);
push(Stack, 3);
push(Stack, 4);
push(Stack, 5);
push(Stack, 6);
push(Stack, 7);
cout<<"min in stack : "<<minInS(Stack)<<endl;
cout<<pop(Stack)->data<<endl;
cout<<"min in stack : "<<minInS(Stack)<<endl;
cout<<pop(Stack)->data<<endl;
cout<<"min in stack : "<<minInS(Stack)<<endl;
cout<<pop(Stack)->data<<endl;
cout<<"min in stack : "<<minInS(Stack)<<endl;
cout<<pop(Stack)->data<<endl;
cout<<"min in stack : "<<minInS(Stack)<<endl;
cout<<pop(Stack)->data<<endl;
cout<<"min in stack : "<<minInS(Stack)<<endl;
cout<<pop(Stack)->data<<endl;
cout<<"min in stack : "<<minInS(Stack)<<endl;
cout<<pop(Stack)->data<<endl;
return 0;
}
Q3.2
最新推荐文章于 2022-04-09 12:46:20 发布