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

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

13.2.2

2019-11-11 07:44:57
字體:
來源:轉載
供稿:網友

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;}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 堆龙德庆县| 格尔木市| 龙川县| 肇庆市| 赣州市| 汉川市| 定兴县| 湄潭县| 怀来县| 托里县| 垦利县| 宝兴县| 河西区| 涞源县| 浪卡子县| 永福县| 珠海市| 桂东县| 潍坊市| 临夏县| 丹江口市| 云和县| 儋州市| 西安市| 阿图什市| 高碑店市| 盐城市| 乐业县| 利川市| 满洲里市| 南溪县| 新兴县| 新津县| 安仁县| 揭东县| 遂昌县| 邹平县| 门源| 宜阳县| 威宁| 平潭县|