国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

13.2.2

2019-11-14 09:12:07
字體:
來源:轉載
供稿:網友

13.27

#include<string>using std::string;class Hasptr {public: HasPtr(const string& s = string()):ps(new string(s)),i(0),use(new size_t(1)) {} HasPtr(const HasPtr& p) :ps(p.ps), i(p.i), use(p.use) { ++use; } HasPtr& Operator=(const HasPtr&); ~HasPtr();PRivate: string* ps; int i; std::size_t* use;};HasPtr::~HasPtr() { if (--*use == 0) { delete ps; delete use; }}HasPtr& HasPtr::operator=(const HasPtr& rhs) { ++*rhs.use; if (--*use == 0) { delete ps; delete use; } ps = rhs.ps; use = rhs.use; i = rhs.i; return *this;}

13.28

#include <string>using std::string;class TreeNode {public: TreeNode() : value(string()), count(new int(1)), left(nullptr), right(nullptr) { } TreeNode(const TreeNode &rhs) : value(rhs.value), count(rhs.count), left(rhs.left), right(rhs.right) { ++*count; } TreeNode& operator=(const TreeNode &rhs); ~TreeNode() { if (--*count == 0) { delete left; delete right; delete count; } }private: std::string value; int *count; TreeNode *left; TreeNode *right;};class BinStrTree {public: BinStrTree() : root(new TreeNode()) { } BinStrTree(const BinStrTree &bst) : root(new TreeNode(*bst.root)) { } BinStrTree& operator=(const BinStrTree &bst); ~BinStrTree() { delete root; }private: TreeNode *root;};TreeNode& TreeNode::operator=(const TreeNode &rhs){ ++*rhs.count; if (--*count == 0) { delete left; delete right; delete count; } value = rhs.value; left = rhs.left; right = rhs.right; count = rhs.count; return *this;}BinStrTree& BinStrTree::operator=(const BinStrTree &bst){ TreeNode *new_root = new TreeNode(*bst.root); delete root; root = new_root; return *this;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 中山市| 四平市| 岚皋县| 肃南| 南靖县| 芜湖市| 祁门县| 荣昌县| 成都市| 涞水县| 西林县| 彰化县| 金山区| 绍兴市| 临朐县| 琼中| 肃北| 永德县| 上林县| 句容市| 太和县| 木里| 邹平县| 浦城县| 阿拉善盟| 齐河县| 吴江市| 新宾| 常山县| 宜章县| 永和县| 乐安县| 固始县| 泗洪县| 房产| 陆丰市| 萝北县| 萨嘎县| 龙井市| 铜川市| 兴城市|