- 博客(10)
- 收藏
- 关注
原创 哈夫曼树以及哈夫曼编码的实现
照搬教材的( #include <stdio.h> #include <stdlib.h> #include <limits.h> #include <string.h> typedef struct { unsigned int weight; unsigned int parent, lchild, rchild; } HTNode, *HuffmanTree; typedef char **HuffmanCode; unsigned
2020-12-06 15:40:24
179
原创 C++高精度整形数加减法模板
#include <bits/stdc++.h> using namespace std; void sum(string a, string b) { vector<int> ans = { 0 }; int dsz = a.size() - b.size(); for (int i = 0; i < dsz; ++i) //先将a不和b进行运算的部分添加 ans.push_back(a[i] - 48); for (int i = 0; i < b.s
2020-09-15 21:03:11
198
原创 二叉树层序遍历
目前实际效果为求每一层的平均值 vector<double> averageOfLevels(TreeNode* root) { auto averages = vector<double>(); //不太清楚为什么都要这样新建容器.... auto q = queue<TreeNode*>(); //queue的特性为先进后出,可以实现当前层所有结点都处于同一队列中,用完就弹出 q.push(root); //根结点 while (!q.empty
2020-09-12 16:14:48
85
原创 第16章 模板与泛型编程
16.4 template<typename itator, typename type> itator find(itator it, type f) { while (*it != f) it++; return it; } #include <iostream> #include <vector> #include <list> #include "head.h" using namespace std; int main() { vec
2020-08-12 17:45:13
118
原创 第14章 重载运算与类型转换
14.36 #include <iostream> #include <string> #include <vector> using namespace std; class ScanfString { public: ScanfString(istream& in = cin) :is(in) {} string operator() () { getline(is, s); return s; } explicit operator
2020-08-12 17:40:42
83
原创 第13章 拷贝控制
13.26 class HasPtr { public: HasPtr() = default; HasPtr(const string& s = string()) : ps(new string(s)), i(0) {} HasPtr(const HasPtr& p) : ps(new string(*p.ps)), i(p.i) {} HasPtr& operator=(const HasPtr& rhs){ auto newp = new str
2020-08-12 17:39:20
141
原创 第12章 动态内存
12.1.1 #include<iostream> #include<fstream> #include<vector> #include<memory> #include<string> using namespace std; class StrBlob { public: typedef vector<string>::size_type size_type; StrBlob() : data(make_shared&l
2020-08-12 17:31:15
81
原创 第11章 关联容器
11.4 #include<iostream> #include<fstream> #include<map> #include<set> #include<string> #include<iterator> #include<algorithm> using namespace std; int main(int argc, char* argv[]) { map<string, size_t> word
2020-08-12 17:25:14
89
原创 第10章 泛型算法
10.24 #include<iostream> #include<vector> #include<list> #include<string> #include<iterator> #include<algorithm> #include<functional> using namespace std; using namespace std::placeholders; bool check_size(int n,
2020-08-12 17:19:00
89
原创 第9章 顺序容器
练习 9.51: #include <iostream> #include <string> using namespace std; struct date { unsigned long y; unsigned long m; unsigned long d; date(string s) { string::size_type pos; string::size_type pos2; pos = s.find_first_of(" /"); stri
2020-08-12 17:13:05
104
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人