6、C++ 面向对象编程:从栈到文件处理的全面解析

C++ 面向对象编程:从栈到文件处理的全面解析

1. 栈与链表

栈在许多应用中非常有价值,并且可以用链表来实现。栈的操作包括在栈顶添加值( push )、检查或移除栈顶值( pop )以及检查栈是否为空。但我们无法对非栈顶的值进行操作。

1.1 栈操作示例

Stack stack;
stack.Push(1);
stack.Push(2);
stack.Push(3);

1.2 类定义

Cell.h
class Cell;
typedef Cell* Link;
class Cell
{
  public:
    Cell(int iValue, Cell* pNextCell);
    int& Value() {return m_iValue;}
    const int Value() const {return m_iValue;}
    Link& NextLink() {return m_pNextLink;}
    const Link NextLink() const {return m_pNextLink;}
  private:
    int m_iValue;
    Link m_pNextLink;
};
Cell.cpp
#include "Cell.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值