NO2包含min函数的栈
来源:互联网 发布:淘宝装修全屏轮播代码 编辑:程序博客网 时间:2024/04/29 21:21
#include<iostream>
#include<stdio.h>
using namespace std;
//typedef int Elemtype;
struct Elemtype
{
int data;
int min;
};
#define MaxSize 1005
class Stack
{
public:
int size;
int top1;
Elemtype myStack[MaxSize];
Stack()
{
size=0;
top1=-1;
}
void push(int data)
{
top1++;
myStack[top1].min=(top1==0?data:min(data,myStack[top1-1].min));
myStack[top1].data=data;
size++;
}
void pop()
{
top1--;
size--;
}
Elemtype top()
{
return myStack[top1];
}
bool empty()
{
if(size<=0)
return true;
return false;
}
};
int main(int argc,char *argv[])
{
freopen("input.txt","r",stdin);
Stack ts;
int num,i,data;
scanf("%d",&num);
for(i=0;i<num;i++)
{
scanf("%d",&data);
ts.push(data);
}
printf("size=%d\n",ts.size);
while(!ts.empty())
{
Elemtype tmp;
tmp=ts.top();
ts.pop();
printf("栈顶元素为:%d,当前最小值为:%d\n",tmp.data,tmp.min);
}
printf("\n");
// puts("\n");
return 0;
}
#include<stdio.h>
using namespace std;
//typedef int Elemtype;
struct Elemtype
{
int data;
int min;
};
#define MaxSize 1005
class Stack
{
public:
int size;
int top1;
Elemtype myStack[MaxSize];
Stack()
{
size=0;
top1=-1;
}
void push(int data)
{
top1++;
myStack[top1].min=(top1==0?data:min(data,myStack[top1-1].min));
myStack[top1].data=data;
size++;
}
void pop()
{
top1--;
size--;
}
Elemtype top()
{
return myStack[top1];
}
bool empty()
{
if(size<=0)
return true;
return false;
}
};
int main(int argc,char *argv[])
{
freopen("input.txt","r",stdin);
Stack ts;
int num,i,data;
scanf("%d",&num);
for(i=0;i<num;i++)
{
scanf("%d",&data);
ts.push(data);
}
printf("size=%d\n",ts.size);
while(!ts.empty())
{
Elemtype tmp;
tmp=ts.top();
ts.pop();
printf("栈顶元素为:%d,当前最小值为:%d\n",tmp.data,tmp.min);
}
printf("\n");
// puts("\n");
return 0;
}
0 0
- NO2包含min函数的栈
- No2、设计包含 min 函数的栈(栈)
- 包含min函数的栈
- 包含min函数的栈
- 包含min函数的栈
- 包含min函数的栈
- 包含min函数的栈
- 包含min函数的栈
- 包含min函数的栈
- 包含min函数的栈
- 包含min函数的栈
- 包含min 函数的栈
- 包含min函数的栈
- 包含min函数的栈
- 包含min函数的栈
- 包含min函数的栈
- 包含min函数的栈
- 包含min函数的栈
- Boost.Bind用法详解(二)
- Linux编辑器之VIM
- NO1把二元查找树转变成排序的双向链表
- usps的 p.o.box 、APO、FPO、DPO
- Java内存区域与内存溢出异常
- NO2包含min函数的栈
- 深入浅出SVM
- ChinaExcel报表平台搭建(二基本查询)
- N03数组的最大子段和
- Linux下配置Opencv2.4.8+Eclipse
- 关于房子关于旅行
- NO4在二叉树中查找和为某值的所有路径
- sift特征提取与分析
- poj2973