Exercise 4.3 E2
来源:互联网 发布:淘宝数据魔方多少钱 编辑:程序博客网 时间:2024/06/05 02:23
E2. What is wrong with the following attempt to use the copy constructor to implement the overloaded assignment operator for a linked Stack?
void Stack::operator=(const Stack&original)
{
Stack new_copy(original);
top_node=new_copy.top_node;
}
How can we modify this code to give a correct implementation?
正解:
void Stack::operator=(const Stack&original)
{
Node*new_top,*new_copy,*original_node=original.top_node;
if(original_node==NULL)
new_top=NULL;
else
{
new_copy=new_top=new Node(origanal_node->entry);
while(original_code->NULL)
{
original_node=original_node->next;
new_copy->next=new Node(original_node->entry);
cew_copy=new_copy->next;
}
}
while(!empty())
pop();
top_node=new_top;
}
- Exercise 4.3 E2
- Exercise 4.2 E2(a) 4.3 E2
- Exercise E2.(b)
- Exercise E2(b)
- Exercise 2.2 E2(b)
- Exercise 4.2 E2
- Exercise 4.1 E2
- exercise 4.1 E2
- Exercise 4.1 E2
- 4.2E2 4.3E2
- Exercise 4.2 E2(a)和Exercise4.3E2
- 作业 Exercise 4.2 E2(a)和Exercise4.3E2
- 4.3E2
- Exercises4.2E2(a)4.3E2
- Exercise 4.2 Exercise 4.3
- 练习4.3 E2 解答
- Exercises 4.3 E2
- E2
- js中xml的基本操作
- HDU-4706 dfs打表
- 开关电源的重要元器件认识
- emacs 的基本操作
- Ipsec Openswan 26sec等基础知识扫盲
- Exercise 4.3 E2
- raspberry pi 远程桌面
- C++版本历史
- Apache Commons fileUpload实现文件上传
- Effective STL
- C++内存回收
- lucene 简单的例子
- 优化系统服务提升Win7系统运行速度
- 大话设计模式六:装饰模式(穿什么有那么重要吗)