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

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

13.2.2

2019-11-11 06:37:30
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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;}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 兰州市| 淮北市| 新竹县| 马山县| 酒泉市| 友谊县| 宜兰县| 奉节县| 大丰市| 夹江县| 河源市| 财经| 通榆县| 仙桃市| 莎车县| 嘉善县| 长兴县| 深泽县| 宿迁市| 安国市| 平潭县| 廉江市| 镇远县| 彭阳县| 濮阳市| 庆元县| 云安县| 金堂县| 彭山县| 莎车县| 丹东市| 广宗县| 横山县| 鞍山市| 邢台县| 荆州市| 清远市| 增城市| 雷州市| 高唐县| 雷州市|