Use the Stack mehod and a temporary Stack to retrieve entries from the Stack source and add
来源:互联网 发布:网络主播人气排行榜 编辑:程序博客网 时间:2024/05/14 18:03
理解:用栈的方法,通过使用临时定义的一个栈,将source栈的元素压到dest栈内,并恢复
source栈。
实现过程:
Error_code copy_stack(Stack&dest,Stack&source)
{
Stack t;
Stack_entry n;
while(!source.empty()&&source.top(n)==success&&source.pop()==success)
{
while(t.push(n)==success&&!t.empty()&&t.top(n)==success&&t.pop()==success)
{
if(source.push(n)==success&&dest.push(n)==success)
return success;
else
return overflow;
}
}
E4
(a) 当n=3时,输出为
321 , 312 , 213 , 231 , 123 ;
(b)当n=4时,输出为
1234, 1243, 1324, 1423, 1432, 2134, 2143,
3124, 3214, 4123, 4132, 4213, 4312, 4321
(c )个数规律为:
C2n n/(n+1)
source栈。
实现过程:
Error_code copy_stack(Stack&dest,Stack&source)
{
Stack t;
Stack_entry n;
while(!source.empty()&&source.top(n)==success&&source.pop()==success)
{
while(t.push(n)==success&&!t.empty()&&t.top(n)==success&&t.pop()==success)
{
if(source.push(n)==success&&dest.push(n)==success)
return success;
else
return overflow;
}
}
E4
(a) 当n=3时,输出为
321 , 312 , 213 , 231 , 123 ;
(b)当n=4时,输出为
1234, 1243, 1324, 1423, 1432, 2134, 2143,
3124, 3214, 4123, 4132, 4213, 4312, 4321
(c )个数规律为:
C2n n/(n+1)
- Use the Stack mehod and a temporary Stack to retrieve entries from the Stack source and add
- Memory Layout And The Stack
- a interface to stack that implement use the fixed array.
- What’s the difference between a stack and a heap?
- the difference between kernel stack and user stack
- Smashing The Stack For Fun And Profit
- C Function Call Conventions and the Stack
- Smashing The Stack For Fun And Profit
- Relation between the main stack and agent
- The difference between stack and heap
- 【DataStructure】The description and usage of Stack
- TaskStackBuilder and extras for the back stack
- [Python]Functions, Variables, and the Call Stack
- C Function Call Conventions and the Stack
- the difference of heap and stack
- Stack----use database and link
- the Stack
- use stack to initial a treeview with the data in a database
- 练习
- 开源(开放源码)
- 求一个连通图的割点,割点的定义是,如果除去此节点和与其相关的边,图不再连通,描述算法
- GPIO相关的重要文件
- VS2005和ASP.NET2.0中使用强类型数据
- Use the Stack mehod and a temporary Stack to retrieve entries from the Stack source and add
- <Linux+qt>设置使用键盘控制事件响应
- 安装SQLServer 2008
- ASP.NET2.0服务器控件之自定义状态管理
- tomcat和servlet
- 第二章
- git学习——基本的分支与合并
- 游戏项目中对CCTableView的使用
- Codeforces Round #197 (Div. 2) c. Xenia and Weights