c++ stacks

堆栈是一个类型的容器的适配器,专门设计在一个LIFO上下文(后进先出),其中元件被插入并只从容器的一端萃取操作。
栈实现为容器适配器,其是使用特定容器类的封装对象作为其底层的容器类,提供一组特定的成员函数来访问它的元素。元件推/从特定的容器,这是被称为堆顶部的“背面”弹出。
底层容器可以是任何标准的容器类模板或一些其它专门设计的容器类。容器应支持以下操作:
ms-help://MS.MSDNQTR.v90.chs/dv_vcstdlib/html/156bba0f-8e4b-4f03-9ae5-cdf09227f5ca.htm

empty	判断是否为空
size	返回堆栈元素的数量
top	返回位于堆栈顶部的引用的元素
push	将一个元素添加到堆栈的顶部
pop	从栈中删除顶部的元素


#include <stack>
#include <vector>
#include <list>
#include <iostream>

//构造函数
void StackConstructor(void);

//判断是否为空
void Stack_empty(void);

//从栈中删除顶部的元素
void Stack_pop(void);

//将一个元素添加到堆栈的顶部
void Stack_push(void);

//返回堆栈元素的数量
void Stack_size(void);

//返回位于堆栈顶部的引用的元素
void Stack_top(void);

int main()
{
	//StackConstructor();
	//Stack_empty();
	//Stack_pop();
	//Stack_push();
	//Stack_size();
	Stack_top();
	return 0;
}

//构造函数
void StackConstructor(void)
{
	using namespace std;

	// Declares stack with default deque base container
	stack <char> dsc1;

	//Explicitly declares a stack with deque base container
	stack <char, deque<char> > dsc2;

	// Declares a stack with vector base containers
	stack <int, vector<int> > vsi1;

	// Declares a stack with list base container
	stack <int, list<int> > lsi;

	// The second member function copies elements from a container
	vector<int> v1;
	v1.push_back(1);
	stack <int, vector<int> > vsi2(v1);
	cout << "The element at the top of stack vsi2 is "
		<< vsi2.top() << "." << endl;

	/*
	The element at the top of stack vsi2 is 1.
	请按任意键继续. . .
	*/
	return;
}

//判断是否为空
void Stack_empty(void)
{
	using namespace std;
	// Declares stacks with default deque base container
	stack <int> s1, s2;

	s1.push(1);

	if (s1.empty())
		cout << "The stack s1 is empty." << endl;
	else
		cout << "The stack s1 is not empty." << endl;

	if (s2.empty())
		cout << "The stack s2 is empty." << endl;
	else
		cout << "The stack s2 is not empty." << endl;

	return;

	/*
	The stack s1 is not empty.
	The stack s2 is empty.
	请按任意键继续. . .
	*/
}

//从栈中删除顶部的元素
void Stack_pop(void)
{
	using namespace std;
	stack <int> s1, s2;

	s1.push(10);
	s1.push(20);
	s1.push(30);

	stack <int>::size_type i;
	i = s1.size();
	cout << "The stack length is " << i << "." << endl;

	i = s1.top();
	cout << "The element at the top of the stack is "
		<< i << "." << endl;

	s1.pop();

	i = s1.size();
	cout << "After a pop, the stack length is "
		<< i << "." << endl;

	i = s1.top();
	cout << "After a pop, the element at the top of the stack is "
		<< i << "." << endl;

	return;

	/*
	The stack length is 3.
	The element at the top of the stack is 30.
	After a pop, the stack length is 2.
	After a pop, the element at the top of the stack is 20.
	请按任意键继续. . .
	*/
}

//将一个元素添加到堆栈的顶部
void Stack_push(void)
{
	using namespace std;
	stack <int> s1;

	s1.push(10);
	s1.push(20);
	s1.push(30);

	stack <int>::size_type i;
	i = s1.size();
	cout << "The stack length is " << i << "." << endl;

	i = s1.top();
	cout << "The element at the top of the stack is "
		<< i << "." << endl;

	return;
	/*
	The stack length is 3.
	The element at the top of the stack is 30.
	请按任意键继续. . .
	*/
}

//返回堆栈元素的数量
void Stack_size(void)
{
	using namespace std;
	stack <int> s1, s2;
	stack <int>::size_type i;

	s1.push(1);
	i = s1.size();
	cout << "The stack length is " << i << "." << endl;

	s1.push(2);
	i = s1.size();
	cout << "The stack length is now " << i << "." << endl;

	return;
	/*
	The stack length is 1.
	The stack length is now 2.
	请按任意键继续. . .
	*/
}

//返回位于堆栈顶部的引用的元素
void Stack_top(void)
{
	using namespace std;
	stack <int> s1;

	s1.push(1);
	s1.push(2);

	int& i = s1.top();
	const int& ii = s1.top();

	cout << "The top integer of the stack s1 is "
		<< i << "." << endl;
	i--;
	cout << "The next integer down is " << ii << "." << endl;

	return;
	/*
	The top integer of the stack s1 is 2.
	The next integer down is 1.
	请按任意键继续. . .
	*/
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
-------------------------------------------- C++ Call Stacks (More useful to developers): -------------------------------------------- Windows not support stack backtrace yet. ------------------------------------------ Python Call Stacks (More useful to users): ------------------------------------------ File "/data/yourenchun/share/projects/renzheng/liuyi/liuyi_env/Python-2.7.14/lib/python2.7/site-packages/paddle/fluid/framework.py", line 1843, in append_op attrs=kwargs.get("attrs", None)) File "/data/yourenchun/share/projects/renzheng/liuyi/liuyi_env/Python-2.7.14/lib/python2.7/site-packages/paddle/fluid/layer_helper.py", line 43, in append_op return self.main_program.current_block().append_op(*args, **kwargs) File "/data/yourenchun/share/projects/renzheng/liuyi/liuyi_env/Python-2.7.14/lib/python2.7/site-packages/paddle/fluid/layers/nn.py", line 9597, in relu6 attrs={'threshold': threshold}) File "/data/yourenchun/share/projects/renzheng/slurm/dist_arcface/models/mnasnet.py", line 171, in conv_bn_layer return fluid.layers.relu6(bn) File "/data/yourenchun/share/projects/renzheng/slurm/dist_arcface/models/mnasnet.py", line 198, in inverted_residual_unit name=name + '_expand') File "/data/yourenchun/share/projects/renzheng/slurm/dist_arcface/models/mnasnet.py", line 252, in invresi_blocks name=name + '_' + str(i + 1)) File "/data/yourenchun/share/projects/renzheng/slurm/dist_arcface/models/mnasnet.py", line 110, in net name='conv' + str(i)) File "test.py", line 107, in run emb = model.net(image) File "test.py", line 318, in main testor.run() File "test.py", line 323, in <module> main() ---------------------- Error Message Summary: ---------------------- Error: Fail to allocate CPU memory: size = 114987136 . [Hint: p should not be null.] at (E:\Paddle\paddle\fluid\memory\detail\system_allocator.cc:61) [operator < relu6 > error]
最新发布
07-12

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值