├── .gitignore ├── Algorithm ├── Algorithm.cpp ├── Algorithm.vcxproj ├── Algorithm.vcxproj.filters ├── ReadMe.txt ├── matrix_udg.cpp ├── matrix_udg.h ├── stdafx.cpp ├── stdafx.h ├── targetver.h └── 动态规划-优化编辑器问题.cpp ├── BasicTest ├── BasicTest.cpp ├── BasicTest.vcxproj ├── BasicTest.vcxproj.filters ├── ReadMe.txt ├── stdafx.cpp ├── stdafx.h └── targetver.h ├── DesignPattern ├── 10组合模式.cs ├── 1单例模式.cs ├── 2简单工厂.cs ├── 3工厂方法.cs ├── 4_2抽象工厂新增工厂.cs ├── 4抽象工厂.cs ├── 5建造者模式.cs ├── 6原型模式.cs ├── 7适配器模式.cs ├── 8桥接模式.cs ├── 9装饰器模式.cs ├── App.config ├── DesignPattern.csproj ├── DesignPattern.sln ├── Form1.Designer.cs ├── Form1.cs ├── Form1.resx ├── Program.cs └── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── HuaWei ├── 10字符个数统计.cpp ├── 11数字颠倒.cpp ├── 12字符串反转.cpp ├── 13句子逆序.cpp ├── 14字串的连接最长路径查找.cpp ├── 15求int型正整数在内存中存储时1的个数.cpp ├── 16购物单.cpp ├── 17坐标移动.cpp ├── 18识别有效的IP地址和掩码并进行分类统计.cpp ├── 19简单错误练习.cpp ├── 1字符串最后一个单词的长度.cpp ├── 20密码验证合格程序.cpp ├── 21简单密码.cpp ├── 22汽水瓶.cpp ├── 23删除字符串中出现次数最少的字符.cpp ├── 24合唱队.cpp ├── 25数据分类处理.cpp ├── 26字符串排序.cpp ├── 27查找兄弟单词.cpp ├── 28素数伴侣.cpp ├── 29字符串加解密.cpp ├── 2计算字符个数.cpp ├── 30字符串合并处理.cpp ├── 31单词倒排.cpp ├── 32字符串运用-密码截取.cpp ├── 33整数与IP地址间的转换.cpp ├── 34图片整理.cpp ├── 35蛇形矩阵.cpp ├── 36字符串加密.cpp ├── 37统计每个月兔子的总数.cpp ├── 38求小球落地5次后所经历的路程和第5次反弹的高度.cpp ├── 39判断两个IP是否属于同一子网.cpp ├── 3明明的随机数.cpp ├── 40输入一行字符,分别统计出包含英文字母空格数字和其它字符的个数.cpp ├── 41称砝码.cpp ├── 42学英语.cpp ├── 43迷宫问题.cpp ├── 44Sudoku.cpp ├── 45名字的漂亮度.cpp ├── 46按字节截取字符串.cpp ├── 47线性插值.cpp ├── 48从单向链表中删除指定值的节点.cpp ├── 49多线程.cpp ├── 4字符串分隔.cpp ├── 50四则运算.cpp ├── 5进制转换.cpp ├── 6质数因子.cpp ├── 7取近似值.cpp ├── 8合并表记录.cpp ├── 9提取不重复的整数.cpp ├── HuaWei.cpp ├── HuaWei.h ├── HuaWei.vcxproj ├── HuaWei.vcxproj.filters ├── ReadMe.txt ├── a清一色.cpp ├── stdafx.cpp ├── stdafx.h ├── targetver.h ├── 成绩排序.cpp ├── 找出字符串中第一个只出现一次的字符.cpp ├── 火车进站.cpp ├── 计算字符串的距离.cpp ├── 高精度整数加法.cpp └── 高精度整数加法.py ├── LICENSE ├── LeetCode ├── LeetCodeCSharp │ ├── App.config │ ├── FormMain.Designer.cs │ ├── FormMain.cs │ ├── FormMain.resx │ ├── LeetCodeCSharp.csproj │ ├── Program.cs │ ├── Properties │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ └── 算法 │ │ ├── 155.cs │ │ ├── 535.cs │ │ ├── 657.cs │ │ ├── 709.cs │ │ ├── 804.cs │ │ ├── 852.cs │ │ └── 867.cs ├── LeetCodeCpp │ ├── 1.cpp │ ├── 101对称二叉树.cpp │ ├── 102二叉树的层次遍历.cpp │ ├── 104.cpp │ ├── 108将有序数组转换为二叉搜索树.cpp │ ├── 111二叉树的最小深度.cpp │ ├── 121.cpp │ ├── 122.cpp │ ├── 125.cpp │ ├── 128.cpp │ ├── 132分隔回文串.cpp │ ├── 136.cpp │ ├── 14.cpp │ ├── 141.cpp │ ├── 15.cpp │ ├── 155.cpp │ ├── 171.cpp │ ├── 189.cpp │ ├── 19.cpp │ ├── 191.cpp │ ├── 198.cpp │ ├── 2.cpp │ ├── 204计数质数.cpp │ ├── 206.cpp │ ├── 21.cpp │ ├── 214.cpp │ ├── 217.cpp │ ├── 220.cpp │ ├── 226翻转二叉树.cpp │ ├── 231.cpp │ ├── 234.cpp │ ├── 237删除链表中的节点.cpp │ ├── 242.cpp │ ├── 278.cpp │ ├── 28.cpp │ ├── 283.cpp │ ├── 3.cpp │ ├── 326.cpp │ ├── 338.cpp │ ├── 342.cpp │ ├── 344.cpp │ ├── 349.cpp │ ├── 350.cpp │ ├── 38.cpp │ ├── 384打乱数组.cpp │ ├── 387.cpp │ ├── 44.cpp │ ├── 46.cpp │ ├── 461.cpp │ ├── 476.cpp │ ├── 48.cpp │ ├── 53.cpp │ ├── 537.cpp │ ├── 617合并二叉树.cpp │ ├── 654最大二叉树.cpp │ ├── 657.cpp │ ├── 7.cpp │ ├── 70.cpp │ ├── 709.cpp │ ├── 728.cpp │ ├── 78.cpp │ ├── 8.cpp │ ├── 814二叉树剪枝.cpp │ ├── 832.cpp │ ├── 846.cpp │ ├── 861.cpp │ ├── 868.cpp │ ├── 88合并两个有序数组.cpp │ ├── 94.cpp │ ├── 98.cpp │ ├── LeetCodeCpp.cpp │ ├── LeetCodeCpp.rc │ ├── LeetCodeCpp.vcxproj │ ├── LeetCodeCpp.vcxproj.filters │ ├── LeetCodeCppTest.h │ ├── ListNode.h │ ├── ReadMe.txt │ ├── TreeNode.h │ ├── resource.h │ ├── stdafx.cpp │ ├── stdafx.h │ └── targetver.h ├── LeetCodePython │ ├── 349.py │ ├── 566.py │ └── LeetCodePython.pyproj └── LeetCodeSql │ ├── 175组合两个表.sql │ ├── 182.sql │ ├── 595.sql │ ├── 620有趣的电影.sql │ ├── LeetCodeSql.vcxproj │ └── LeetCodeSql.vcxproj.filters ├── LinkList ├── LinkList.vcxproj ├── LinkList.vcxproj.filters ├── ReadMe.txt ├── josephu_problem.cpp ├── link_list.cpp ├── link_list.h ├── link_list_main.cpp ├── single_curcular_linked_list.cpp ├── stdafx.cpp ├── stdafx.h └── targetver.h ├── README.md ├── STL ├── ReadMe.txt ├── STL.vcxproj ├── STL.vcxproj.filters ├── list.cpp ├── map.cpp ├── set.cpp ├── stdafx.cpp ├── stdafx.h ├── stl_demo.h ├── stl_main.cpp ├── targetver.h ├── vector.cpp └── 常用算法.cpp ├── Search ├── ReadMe.txt ├── Search.vcxproj ├── Search.vcxproj.filters ├── binary_search.cpp ├── block_search.cpp ├── fibonacci_search.cpp ├── hash_search.cpp ├── insertion_search.cpp ├── search.h ├── search_main.cpp ├── sequence_search.cpp ├── stdafx.cpp ├── stdafx.h ├── targetver.h ├── tree_search.cpp └── 性能对比.jpg ├── Stack ├── ReadMe.txt ├── Stack.vcxproj ├── Stack.vcxproj.filters ├── StackDemo.h ├── array_stack.cpp ├── stack_main.cpp ├── stdafx.cpp ├── stdafx.h └── targetver.h ├── Test ├── LeetCodeCppTest │ ├── LeetCodeCppTest.vcxproj │ ├── LeetCodeCppTest.vcxproj.filters │ ├── stdafx.cpp │ ├── stdafx.h │ ├── targetver.h │ └── unittest1.cpp ├── STLTest │ ├── STLTest.vcxproj │ ├── STLTest.vcxproj.filters │ ├── stdafx.cpp │ ├── stdafx.h │ ├── targetver.h │ └── unittest_stl.cpp ├── SearchTest │ ├── SearchTest.vcxproj │ ├── SearchTest.vcxproj.filters │ ├── stdafx.cpp │ ├── stdafx.h │ ├── targetver.h │ └── unittest_search.cpp └── SortTest │ ├── UnitTest1.vcxproj │ ├── UnitTest1.vcxproj.filters │ ├── stdafx.cpp │ ├── stdafx.h │ ├── targetver.h │ └── unittest_sort.cpp ├── ThreadCSharp ├── App.config ├── Form1.Designer.cs ├── Form1.cs ├── Form1.resx ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings └── ThreadCSharp.csproj ├── ThreadCpp ├── 1_thread.cpp ├── 2_move.cpp ├── 3_mutex.cpp ├── 4_timed_mutex.cpp ├── 5_thread_local_storage.cpp ├── 6_condition_variable.cpp ├── 7_atomic.cpp ├── 8_call_once.cpp ├── ReadMe.md ├── ThreadCpp.cpp ├── ThreadCpp.vcxproj ├── ThreadCpp.vcxproj.filters ├── ThreadLearning.h ├── stdafx.cpp ├── stdafx.h └── targetver.h ├── TreeCpp ├── BiTree.h ├── Huffman.h ├── HuffmanNode.h ├── MinHeap.h ├── ReadMe.txt ├── TreeCpp.vcxproj ├── TreeCpp.vcxproj.filters ├── TreeCpp_main.cpp ├── stdafx.cpp ├── stdafx.h └── targetver.h ├── string ├── ReadMe.txt ├── stdafx.cpp ├── stdafx.h ├── string.cpp ├── string.vcxproj ├── string.vcxproj.filters └── targetver.h ├── templateDemo ├── BiTree.cpp ├── BiTree.h ├── ReadMe.txt ├── stdafx.cpp ├── stdafx.h ├── targetver.h ├── templateDemo.cpp ├── templateDemo.vcxproj └── templateDemo.vcxproj.filters ├── 基础 ├── 位运算 │ ├── BitOperation.cpp │ ├── BitOperation.h │ ├── ReadMe.txt │ ├── stdafx.cpp │ ├── stdafx.h │ ├── targetver.h │ ├── 位运算.cpp │ ├── 位运算.vcxproj │ └── 位运算.vcxproj.filters ├── 内存管理 │ └── memory │ │ ├── ReadMe.md │ │ ├── memory.cpp │ │ ├── memory.vcxproj │ │ ├── memory.vcxproj.filters │ │ ├── stdafx.cpp │ │ ├── stdafx.h │ │ └── targetver.h └── 指针 │ └── pointer │ ├── ReadMe.md │ ├── pointer.cpp │ ├── pointer.vcxproj │ ├── pointer.vcxproj.filters │ ├── ptr.h │ ├── stdafx.cpp │ ├── stdafx.h │ ├── targetver.h │ └── unique_ptr_demo.cpp ├── 排序 ├── ReadMe.txt ├── insertion_sort.cpp ├── merge_sort.cpp ├── selection_sort.cpp ├── sort.h ├── sort_main.cpp ├── stdafx.cpp ├── stdafx.h ├── swap_sort.cpp ├── targetver.h ├── 排序.vcxproj ├── 排序.vcxproj.filters └── 算法复杂度表格.png └── 面试基础.sln /Algorithm/Algorithm.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Algorithm/Algorithm.cpp -------------------------------------------------------------------------------- /Algorithm/Algorithm.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 32 | 33 | 源文件 34 | 35 | 36 | 源文件 37 | 38 | 39 | 源文件 40 | 41 | 42 | 源文件 43 | 44 | 45 | -------------------------------------------------------------------------------- /Algorithm/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:Algorithm 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 Algorithm 应用程序。 6 | 7 | 本文件概要介绍组成 Algorithm 应用程序的每个文件的内容。 8 | 9 | 10 | Algorithm.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | Algorithm.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | Algorithm.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 Algorithm.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /Algorithm/matrix_udg.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Algorithm/matrix_udg.cpp -------------------------------------------------------------------------------- /Algorithm/matrix_udg.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Algorithm/matrix_udg.h -------------------------------------------------------------------------------- /Algorithm/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Algorithm/stdafx.cpp -------------------------------------------------------------------------------- /Algorithm/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Algorithm/stdafx.h -------------------------------------------------------------------------------- /Algorithm/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Algorithm/targetver.h -------------------------------------------------------------------------------- /Algorithm/动态规划-优化编辑器问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Algorithm/动态规划-优化编辑器问题.cpp -------------------------------------------------------------------------------- /BasicTest/BasicTest.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/BasicTest/BasicTest.cpp -------------------------------------------------------------------------------- /BasicTest/BasicTest.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 29 | 30 | 源文件 31 | 32 | 33 | 源文件 34 | 35 | 36 | -------------------------------------------------------------------------------- /BasicTest/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:BasicTest 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 BasicTest 应用程序。 6 | 7 | 本文件概要介绍组成 BasicTest 应用程序的每个文件的内容。 8 | 9 | 10 | BasicTest.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | BasicTest.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | BasicTest.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 BasicTest.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /BasicTest/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/BasicTest/stdafx.cpp -------------------------------------------------------------------------------- /BasicTest/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/BasicTest/stdafx.h -------------------------------------------------------------------------------- /BasicTest/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/BasicTest/targetver.h -------------------------------------------------------------------------------- /DesignPattern/1单例模式.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DesignPattern 7 | { 8 | #region 原理版 9 | 10 | /// 11 | /// 单线程版单例模式 12 | /// 13 | public class Singleton_0 14 | { 15 | // 定义一个静态变量来保存类的实例 16 | private static Singleton_0 uniqueInstance; 17 | 18 | // 定义私有构造函数,使外界不能创建该类实例 19 | private Singleton_0() 20 | { 21 | } 22 | 23 | /// 24 | /// 定义公有方法提供一个全局访问点,同时你也可以定义公有属性来提供全局访问点 25 | /// 26 | /// 27 | public static Singleton_0 GetInstance() 28 | { 29 | // 如果类的实例不存在则创建,否则直接返回 30 | if (uniqueInstance == null) 31 | { 32 | uniqueInstance = new Singleton_0(); 33 | } 34 | return uniqueInstance; 35 | } 36 | } 37 | 38 | /// 39 | /// 多线程下单例模式的实现 40 | /// 41 | public class Singleton_s 42 | { 43 | // 定义一个静态变量来保存类的实例 44 | private static Singleton_s uniqueInstance; 45 | 46 | // 定义一个标识确保线程同步 47 | private static readonly object locker = new object(); 48 | 49 | // 定义私有构造函数,使外界不能创建该类实例 50 | private Singleton_s() 51 | { 52 | } 53 | 54 | /// 55 | /// 定义公有方法提供一个全局访问点,同时你也可以定义公有属性来提供全局访问点 56 | /// 57 | /// 58 | public static Singleton_s GetInstance() 59 | { 60 | // 当第一个线程运行到这里时,此时会对locker对象 "加锁", 61 | // 当第二个线程运行该方法时,首先检测到locker对象为"加锁"状态,该线程就会挂起等待第一个线程解锁 62 | // lock语句运行完之后(即线程运行完之后)会对该对象"解锁" 63 | // 双重锁定只需要一句判断就可以了 64 | if (uniqueInstance == null) 65 | { 66 | lock (locker) 67 | { 68 | // 如果类的实例不存在则创建,否则直接返回 69 | if (uniqueInstance == null) 70 | { 71 | uniqueInstance = new Singleton_s(); 72 | } 73 | } 74 | } 75 | return uniqueInstance; 76 | } 77 | } 78 | 79 | #endregion 80 | 81 | #region 我的测试用实例 82 | 83 | /// 84 | /// 多线程下单例模式的实现 85 | /// 86 | public class Singleton_t 87 | { 88 | // 定义一个静态变量来保存类的实例 89 | private static Singleton_t uniqueInstance; 90 | 91 | // 定义一个标识确保线程同步 92 | private static readonly object locker = new object(); 93 | 94 | // 定义私有构造函数,使外界不能创建该类实例 95 | private Singleton_t() 96 | { 97 | } 98 | 99 | /// 100 | /// 定义公有方法提供一个全局访问点,同时你也可以定义公有属性来提供全局访问点 101 | /// 102 | /// 103 | public static Singleton_t GetInstance() 104 | { 105 | // 当第一个线程运行到这里时,此时会对locker对象 "加锁", 106 | // 当第二个线程运行该方法时,首先检测到locker对象为"加锁"状态,该线程就会挂起等待第一个线程解锁 107 | // lock语句运行完之后(即线程运行完之后)会对该对象"解锁" 108 | // 双重锁定只需要一句判断就可以了 109 | if (uniqueInstance == null) 110 | { 111 | lock (locker) 112 | { 113 | // 如果类的实例不存在则创建,否则直接返回 114 | if (uniqueInstance == null) 115 | { 116 | uniqueInstance = new Singleton_t(); 117 | } 118 | } 119 | } 120 | return uniqueInstance; 121 | } 122 | 123 | #region 数据 124 | public int data = 0; 125 | public string strData = "0"; 126 | #endregion 127 | } 128 | 129 | #endregion 130 | } 131 | -------------------------------------------------------------------------------- /DesignPattern/2简单工厂.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DesignPattern.Factory 7 | { 8 | #region 参考教程的示例 9 | 10 | /// 11 | /// 菜抽象类 12 | /// 13 | public abstract class Food 14 | { 15 | public string FoodName { get; set; } 16 | 17 | // 输出点了什么菜 18 | public abstract void Print(); 19 | } 20 | 21 | /// 22 | /// 西红柿炒鸡蛋这道菜 23 | /// 24 | public class TomatoScrambledEggs : Food 25 | { 26 | public override void Print() 27 | { 28 | FoodName = "一份西红柿炒蛋!"; 29 | Console.WriteLine(FoodName); 30 | } 31 | } 32 | 33 | /// 34 | /// 土豆肉丝这道菜 35 | /// 36 | public class ShreddedPorkWithPotatoes : Food 37 | { 38 | public override void Print() 39 | { 40 | FoodName = "一份土豆肉丝"; 41 | Console.WriteLine("一份土豆肉丝"); 42 | } 43 | } 44 | 45 | /// 46 | /// 简单工厂类, 负责 炒菜 47 | /// 48 | public class FoodSimpleFactory 49 | { 50 | public static Food CreateFood(string type) 51 | { 52 | Food food = null; 53 | //equals比较两个string对象的值 54 | //==比较两个string对象是否是同一个引用,建议用equals 55 | if (type.Equals("土豆肉丝")) 56 | { 57 | food = new ShreddedPorkWithPotatoes(); 58 | } 59 | else if (type.Equals("西红柿炒蛋")) 60 | { 61 | food = new TomatoScrambledEggs(); 62 | } 63 | 64 | return food; 65 | } 66 | } 67 | 68 | #endregion 69 | 70 | #region 根据教程理解自己写的示例 71 | 72 | /// 73 | /// 设备抽象接口 74 | /// 75 | public interface IEquip 76 | { 77 | string GetName(); 78 | } 79 | 80 | /// 81 | /// 简单工厂模式的工厂 82 | /// 83 | public class EquipSimpleFactory 84 | { 85 | private static IEquip factory = null; 86 | 87 | public static IEquip CreateFactory(string name) 88 | { 89 | switch (name) 90 | { 91 | case "gps": 92 | factory = new Gps(); 93 | break; 94 | case "imu": 95 | factory = new IMU(); 96 | break; 97 | default: 98 | throw new NotImplementedException(); 99 | } 100 | return factory; 101 | } 102 | } 103 | 104 | /// 105 | /// GPS设备 106 | /// 107 | public class Gps : IEquip 108 | { 109 | public string GetName() 110 | { 111 | return nameof(Gps); 112 | } 113 | } 114 | 115 | /// 116 | /// 惯性测量单元设备 117 | /// 118 | public class IMU : IEquip 119 | { 120 | public string GetName() 121 | { 122 | return nameof(IMU); 123 | } 124 | } 125 | 126 | #endregion 127 | } 128 | -------------------------------------------------------------------------------- /DesignPattern/3工厂方法.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DesignPattern.Factory 7 | { 8 | #region 教程版 9 | 10 | public abstract class Creator 11 | { 12 | public abstract Food CreateFoddFactory(); 13 | } 14 | 15 | /// 16 | /// 肉末茄子这道菜 17 | /// 18 | public class MincedMeatEggplant : Food 19 | { 20 | /// 21 | /// 重写抽象类中的方法 22 | /// 23 | public override void Print() 24 | { 25 | FoodName = "肉末茄子好了"; 26 | Console.WriteLine("肉末茄子好了"); 27 | } 28 | } 29 | /// 30 | /// 肉末茄子工厂类,负责创建肉末茄子这道菜 31 | /// 32 | public class MincedMeatEggplantFactory : Creator 33 | { 34 | /// 35 | /// 负责创建肉末茄子这道菜 36 | /// 37 | /// 38 | public override Food CreateFoddFactory() 39 | { 40 | return new MincedMeatEggplant(); 41 | } 42 | } 43 | 44 | #endregion 45 | 46 | #region 根据教程理解自己写的示例 47 | 48 | public interface IEquipCreator 49 | { 50 | IEquip CreateFactory(); 51 | } 52 | 53 | /// 54 | /// gps的工厂方法 55 | /// 56 | public class GpsFactory : IEquipCreator 57 | { 58 | public IEquip CreateFactory() 59 | { 60 | return new Gps(); 61 | } 62 | } 63 | 64 | /// 65 | /// 惯性测量单元的工厂方法 66 | /// 67 | public class IMUFactory : IEquipCreator 68 | { 69 | public IEquip CreateFactory() 70 | { 71 | return new IMU(); 72 | } 73 | } 74 | 75 | /// 76 | /// 摄像头工厂方法 77 | /// 78 | public class CameraFactory : IEquipCreator 79 | { 80 | public IEquip CreateFactory() 81 | { 82 | return new Camera(); 83 | } 84 | } 85 | 86 | /// 87 | /// 摄像头设备 88 | /// 89 | public class Camera : IEquip 90 | { 91 | public string GetName() 92 | { 93 | return nameof(Camera); 94 | } 95 | } 96 | 97 | #endregion 98 | 99 | } 100 | -------------------------------------------------------------------------------- /DesignPattern/4_2抽象工厂新增工厂.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DesignPattern.Factory 7 | { 8 | #region 教程 9 | 10 | /// 11 | /// 如果绝味又想开一家湖南的分店时,因为湖南喜欢吃麻的 12 | /// 所以这是有需要有一家湖南的工厂专门制作 13 | /// 14 | public class HuNanFactory : AbstractFactory 15 | { 16 | // 制作湖南鸭脖 17 | public override YaBo CreateYaBo() 18 | { 19 | return new HuNanYaBo(); 20 | } 21 | 22 | // 制作湖南鸭架 23 | public override YaJia CreateYaJia() 24 | { 25 | return new HuNanYajia(); 26 | } 27 | } 28 | 29 | /// 30 | /// 湖南的鸭脖 31 | /// 32 | public class HuNanYaBo : YaBo 33 | { 34 | public override void Print() 35 | { 36 | Console.WriteLine("湖南的鸭脖"); 37 | } 38 | } 39 | 40 | /// 41 | /// 湖南的鸭架 42 | /// 43 | public class HuNanYajia : YaJia 44 | { 45 | public override void Print() 46 | { 47 | Console.WriteLine("湖南的鸭架子"); 48 | } 49 | } 50 | 51 | #endregion 52 | 53 | #region 自己写的 54 | 55 | #endregion 56 | } 57 | -------------------------------------------------------------------------------- /DesignPattern/7适配器模式.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace DesignPattern.Adapter 7 | { 8 | #region 教程 9 | 10 | /// 11 | /// 客户端,客户想要把2个孔的插头 转变成三个孔的插头,这个转变交给适配器就好 12 | /// 既然适配器需要完成这个功能,所以它必须同时具体2个孔插头和三个孔插头的特征 13 | /// 14 | public class Client 15 | { 16 | public static void test() 17 | { 18 | // 现在客户端可以通过电适配要使用2个孔的插头了 19 | IThreeHole threehole = new PowerAdapter(); 20 | threehole.Request(); 21 | Console.ReadLine(); 22 | } 23 | } 24 | 25 | /// 26 | /// 三个孔的插头,也就是适配器模式中的目标角色 27 | /// 28 | public interface IThreeHole 29 | { 30 | void Request(); 31 | } 32 | 33 | /// 34 | /// 两个孔的插头,源角色——需要适配的类 35 | /// 36 | public abstract class TwoHole 37 | { 38 | public void SpecificRequest() 39 | { 40 | Console.WriteLine("我是两个孔的插头"); 41 | } 42 | } 43 | 44 | /// 45 | /// 适配器类,接口要放在类的后面 46 | /// 适配器类提供了三个孔插头的行为,但其本质是调用两个孔插头的方法 47 | /// 48 | public class PowerAdapter : TwoHole, IThreeHole 49 | { 50 | /// 51 | /// 实现三个孔插头接口方法 52 | /// 53 | public void Request() 54 | { 55 | // 调用两个孔插头方法 56 | this.SpecificRequest(); 57 | } 58 | } 59 | 60 | 61 | #endregion 62 | 63 | #region 自己写一遍 64 | 65 | /// 66 | /// 客户端 67 | /// 68 | public class MyClient 69 | { 70 | public static void test() 71 | { 72 | //新的usb接口行为和旧的一样,都是插进去 73 | //但是usb形状不一样(函数接口不一样) 74 | //适配器模型转换一下就能调用旧接口了 75 | ITypeC typeC = new TypeC(); 76 | typeC.NewUsb(); 77 | Console.ReadLine(); 78 | } 79 | } 80 | 81 | /// 82 | /// 新插头,也就是适配器模式中的目标角色 83 | /// 84 | public interface ITypeC 85 | { 86 | void NewUsb(); 87 | } 88 | 89 | /// 90 | /// 早期的手机usb接口,源角色——需要适配的类 91 | /// 92 | public abstract class MicroUSB 93 | { 94 | public void OldUsb() 95 | { 96 | Console.WriteLine(nameof(MicroUSB)+"插入"); 97 | } 98 | } 99 | 100 | /// 101 | /// 适配器类,接口要放在类的后面 102 | /// 适配器类提供了新的插头,但其本质是调用旧插头的方法 103 | /// 104 | public class TypeC : MicroUSB, ITypeC 105 | { 106 | /// 107 | /// 实现新的插头方法 108 | /// 109 | public void NewUsb() 110 | { 111 | // 调用旧插头方法 112 | this.OldUsb(); 113 | } 114 | } 115 | 116 | 117 | #endregion 118 | } 119 | -------------------------------------------------------------------------------- /DesignPattern/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /DesignPattern/DesignPattern.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DesignPattern", "DesignPattern\DesignPattern.csproj", "{33B1CF6A-2913-4B0D-937D-C7B5BBA00DAF}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {33B1CF6A-2913-4B0D-937D-C7B5BBA00DAF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {33B1CF6A-2913-4B0D-937D-C7B5BBA00DAF}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {33B1CF6A-2913-4B0D-937D-C7B5BBA00DAF}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {33B1CF6A-2913-4B0D-937D-C7B5BBA00DAF}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /DesignPattern/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Windows.Forms; 5 | 6 | namespace DesignPattern 7 | { 8 | static class Program 9 | { 10 | /// 11 | /// 应用程序的主入口点。 12 | /// 13 | [STAThread] 14 | static void Main() 15 | { 16 | Application.EnableVisualStyles(); 17 | Application.SetCompatibleTextRenderingDefault(false); 18 | Application.Run(new Form1()); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /DesignPattern/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("DesignPattern")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("DesignPattern")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | //将 ComVisible 设置为 false 将使此程序集中的类型 18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("33b1cf6a-2913-4b0d-937d-c7b5bba00daf")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /DesignPattern/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本: 4.0.30319.42000 5 | // 6 | // 对此文件的更改可能导致不正确的行为,如果 7 | // 重新生成代码,则所做更改将丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace DesignPattern.Properties 12 | { 13 | 14 | 15 | /// 16 | /// 强类型资源类,用于查找本地化字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// 返回此类使用的缓存 ResourceManager 实例。 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DesignPattern.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// 覆盖当前线程的 CurrentUICulture 属性 56 | /// 使用此强类型的资源类的资源查找。 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /DesignPattern/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace DesignPattern.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /DesignPattern/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /HuaWei/10字符个数统计.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | int test_10() 12 | { 13 | string str; 14 | while (cin >> str) 15 | { 16 | int sum = 0; 17 | set s(str.begin(), str.end()); 18 | cout << s.size() << endl; 19 | } 20 | return 0; 21 | } -------------------------------------------------------------------------------- /HuaWei/11数字颠倒.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | int test_11() 12 | { 13 | string str; 14 | while (cin >> str) 15 | { 16 | int size = str.size(); 17 | for (int i = 0;i 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | static void method_1(string str) 13 | { 14 | int size = str.size(); 15 | for (int i = 0;i> str) 32 | { 33 | method_2(str); 34 | } 35 | return 0; 36 | } -------------------------------------------------------------------------------- /HuaWei/13句子逆序.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | static void method_1(string str) 13 | { 14 | string tmp; 15 | int space = str.find_last_of(" "); 16 | while (space>0) 17 | { 18 | tmp = str.substr(space + 1, str.size() - space - 1); 19 | cout << tmp << " "; 20 | str = str.substr(0, space); 21 | space = str.find_last_of(" "); 22 | } 23 | cout << str << endl; 24 | } 25 | 26 | static void method_2(string str) 27 | { 28 | string tmp = ""; 29 | vector vec; 30 | for (int i = 0;i 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | bool compare(const string& a, const string& b) 13 | { 14 | return a> n) 21 | { 22 | vector vec; 23 | string tmp; 24 | for (int i = 0;i> tmp; 27 | vec.push_back(tmp); 28 | } 29 | sort(vec.begin(), vec.end(), compare); 30 | for (auto it = vec.begin();it != vec.end();it++) 31 | { 32 | cout << *it << endl; 33 | } 34 | } 35 | return 0; 36 | } -------------------------------------------------------------------------------- /HuaWei/15求int型正整数在内存中存储时1的个数.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | void CountOne(int n) 13 | { 14 | int sum = 0; 15 | while (n != 0) 16 | { 17 | if (n & 1) sum++; 18 | n = n >> 1; 19 | } 20 | cout << sum; 21 | } 22 | 23 | int test_15() 24 | { 25 | int n; 26 | while (cin >> n) 27 | { 28 | CountOne(n); 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /HuaWei/16购物单.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/16购物单.cpp -------------------------------------------------------------------------------- /HuaWei/17坐标移动.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | using namespace std; 11 | 12 | int test_17() 13 | { 14 | string str; 15 | while (cin >> str) 16 | { 17 | int x = 0, y = 0; 18 | while (str.size()>1) 19 | { 20 | int sep = str.find(";"); 21 | string tmp = str.substr(1, sep - 1); 22 | if (tmp.size() == 1 || tmp.size() == 2) 23 | { 24 | char *offset; 25 | int inext = strtol(tmp.c_str(), &offset, 10); 26 | switch (str[0]) { 27 | case 'A': 28 | x -= inext; 29 | break; 30 | case 'D': 31 | x += inext; 32 | break; 33 | case 'W': 34 | y += inext; 35 | break; 36 | case 'S': 37 | y -= inext; 38 | break; 39 | default: 40 | break; 41 | } 42 | } 43 | str = str.substr(sep + 1, str.size() - sep - 1); 44 | } 45 | cout << x << "," << y << endl; 46 | } 47 | return 0; 48 | } -------------------------------------------------------------------------------- /HuaWei/18识别有效的IP地址和掩码并进行分类统计.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/18识别有效的IP地址和掩码并进行分类统计.cpp -------------------------------------------------------------------------------- /HuaWei/19简单错误练习.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/19简单错误练习.cpp -------------------------------------------------------------------------------- /HuaWei/1字符串最后一个单词的长度.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int test_1() 8 | { 9 | string str; 10 | getline(cin, str); 11 | int end = str.find_last_of(' '); 12 | string last(str, end + 1, str.size() - end); 13 | cout << last.size(); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /HuaWei/20密码验证合格程序.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | bool isAtLeastThree(const string& str) 14 | { 15 | bool lower = false, upper = false, nums = false, other = false; 16 | for (int i = 0;i= 'a'&&str.at(i) <= 'z') lower = true; 19 | //else if (str.at(i) >= 'A'&&str.at(i) <= 'Z') upper = true; 20 | //else if (str.at(i) >= '0'&&str.at(i) <= '9') nums = true; 21 | if (islower(str[i])) lower = true; 22 | else if (isupper(str[i])) upper = true; 23 | else if (isdigit(str[i])) nums = true; 24 | else other = true; 25 | } 26 | return (lower + upper + nums + other) >= 3; 27 | } 28 | 29 | bool isSameMoreTwo(const string& str) 30 | { 31 | for (int i = 0; i <= str.size() - 6; i++) 32 | { 33 | for (int j = i + 3;j < str.size();j++) 34 | { 35 | if (str[i] == str[j] && str[i + 1] == str[j + 1] && str[i + 2] == str[j + 2]) 36 | { 37 | return false; 38 | } 39 | } 40 | } 41 | return true; 42 | } 43 | 44 | int test_20() 45 | { 46 | string str; 47 | while (getline(cin, str)) 48 | { 49 | bool is_ok = true; 50 | if (str.size() <= 8) is_ok = false; 51 | else if (!isAtLeastThree(str)) is_ok = false; 52 | else if (!isSameMoreTwo(str)) is_ok = false; 53 | if (is_ok) 54 | cout << "OK" << endl; 55 | else 56 | cout << "NG" << endl; 57 | } 58 | return 0; 59 | } -------------------------------------------------------------------------------- /HuaWei/21简单密码.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | string Upper2Pwd(const char& str) 14 | { 15 | string ret; 16 | if (str >= 'A'&&str <= 'Y') ret = str - 'A' + 'a' + 1; 17 | else ret = 'a'; 18 | return ret; 19 | } 20 | 21 | string Lower2Pwd(const char& str) 22 | { 23 | string ret; 24 | if (str >= 'a'&&str <= 'c') ret = '2'; 25 | else if (str >= 'd'&&str <= 'f') ret = '3'; 26 | else if (str >= 'g'&&str <= 'i') ret = '4'; 27 | else if (str >= 'j'&&str <= 'l') ret = '5'; 28 | else if (str >= 'm'&&str <= 'o') ret = '6'; 29 | else if (str >= 'p'&&str <= 's') ret = '7'; 30 | else if (str >= 't'&&str <= 'v') ret = '8'; 31 | else ret = '9'; 32 | return ret; 33 | } 34 | 35 | int test_21() 36 | { 37 | string str; 38 | while (cin >> str) 39 | { 40 | string tmp; 41 | for (int i = 0;i= 'a'&&str.at(i) <= 'z') 44 | tmp += Lower2Pwd(str.at(i)); 45 | else if (str.at(i) >= 'A'&&str.at(i) <= 'Z') 46 | tmp += Upper2Pwd(str.at(i)); 47 | else 48 | tmp += str.at(i); 49 | } 50 | cout << tmp << endl; 51 | } 52 | return 0; 53 | } -------------------------------------------------------------------------------- /HuaWei/22汽水瓶.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | int test_22() 14 | { 15 | int n; 16 | while (cin >> n) 17 | { 18 | if (n == 0) 19 | break; 20 | int sum = 0; 21 | while (n >= 2) 22 | { 23 | if (n == 2) 24 | { 25 | sum++; 26 | break; 27 | } 28 | 29 | sum += n / 3; 30 | n = n / 3 + n % 3; 31 | } 32 | cout << sum << endl; 33 | } 34 | return 0; 35 | } -------------------------------------------------------------------------------- /HuaWei/23删除字符串中出现次数最少的字符.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/23删除字符串中出现次数最少的字符.cpp -------------------------------------------------------------------------------- /HuaWei/24合唱队.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | int test_24() 14 | { 15 | int N; 16 | while (cin >> N) 17 | { 18 | vectordata(N, 0); 19 | for (int i = 0; i < N; i++) 20 | cin >> data[i]; 21 | //cout << endl; 22 | vectordp_increase(N, 0); 23 | for (int i = 1; i < N; i++) { 24 | for (int j = 0; j < i; j++) 25 | if (data[i] > data[j]) 26 | dp_increase[i] = max(dp_increase[i], dp_increase[j] + 1); 27 | } 28 | vectordp_decrease(N, 0); 29 | for (int i = N - 1; i >= 0; i--) { 30 | for (int j = i + 1; j < N; j++) 31 | if (data[j] < data[i]) 32 | dp_decrease[i] = max(dp_decrease[i], dp_decrease[j] + 1); 33 | } 34 | 35 | 36 | for (int i = 0; i < N; i++) { 37 | dp_decrease[i] += dp_increase[i]; 38 | } 39 | cout << N - (*max_element(dp_decrease.begin() + 1, dp_decrease.end() - 1) + 1) << endl; 40 | } 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /HuaWei/25数据分类处理.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/25数据分类处理.cpp -------------------------------------------------------------------------------- /HuaWei/26字符串排序.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/26字符串排序.cpp -------------------------------------------------------------------------------- /HuaWei/27查找兄弟单词.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | bool comparestr(string s1, string s2) 14 | { 15 | if (s1 == s2) 16 | { 17 | return false; 18 | } 19 | sort(s1.begin(), s1.end()); 20 | sort(s2.begin(), s2.end()); 21 | if (s1 == s2) 22 | { 23 | return true; 24 | } 25 | else 26 | { 27 | return false; 28 | } 29 | } 30 | 31 | int test_27() 32 | { 33 | int num; 34 | string str[1000]; 35 | vectorvec; 36 | vector::iterator it; 37 | while (cin >> num) 38 | { 39 | int i = 0, j = 0, icount = 0, index, k = 1; 40 | string searchword, str, indexword; 41 | vec.clear(); 42 | for (i = 0;i> str; 45 | vec.push_back(str); 46 | } 47 | sort(vec.begin(), vec.end()); 48 | cin >> searchword; 49 | cin >> index; 50 | 51 | for (i = 0;i= index) 68 | { 69 | cout << indexword << endl; 70 | } 71 | } 72 | return 0; 73 | } -------------------------------------------------------------------------------- /HuaWei/28素数伴侣.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/28素数伴侣.cpp -------------------------------------------------------------------------------- /HuaWei/29字符串加解密.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | using namespace std; 13 | 14 | char encrypt[] = { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" }; 15 | char decryp[] = { "bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA1234567890" }; 16 | void Encrypt(char aucPassword[], char aucResult[]) { 17 | int i = 0; 18 | while (aucPassword[i] != '\0') { 19 | if (aucPassword[i] >= '0'&&aucPassword[i] <= '9') 20 | aucResult[i] = decryp[aucPassword[i] - '0' + 52]; 21 | else if (aucPassword[i] >= 'A'&&aucPassword[i] <= 'Z') 22 | aucResult[i] = decryp[aucPassword[i] - 'A']; 23 | else if (aucPassword[i] >= 'a'&&aucPassword[i] <= 'z') 24 | aucResult[i] = decryp[aucPassword[i] - 'a' + 26]; 25 | cout << aucResult[i++]; 26 | } 27 | cout << endl; 28 | return; 29 | } 30 | 31 | int unEncrypt(char result[], char password[]) { 32 | int i = 0; 33 | while (password[i] != '\0') { 34 | if (password[i] > '0'&&password[i] <= '9') 35 | result[i] = encrypt[password[i] - '1' + 52]; 36 | else if (password[i] == '0') 37 | result[i] = '9'; 38 | else if (password[i] > 'A'&&password[i] <= 'Z') 39 | result[i] = encrypt[password[i] - 'B' + 26]; 40 | else if (password[i] == 'A') 41 | result[i] = 'z'; 42 | else if (password[i] > 'a'&&password[i] <= 'z') 43 | result[i] = encrypt[password[i] - 'b']; 44 | else if (password[i] == 'a') 45 | result[i] = 'Z'; 46 | cout << result[i++]; 47 | } 48 | cout << endl; 49 | return 0; 50 | } 51 | 52 | int test_29() { 53 | char aucPassword[100]; 54 | while (cin >> aucPassword) { 55 | char aucResult[100], password[100], result[100]; 56 | cin >> password; 57 | Encrypt(aucPassword, aucResult); 58 | int ans = unEncrypt(result, password); 59 | } 60 | return 0; 61 | } -------------------------------------------------------------------------------- /HuaWei/2计算字符个数.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int test_2() 8 | { 9 | string str; 10 | char up; 11 | char low; 12 | cin >> str >> up; 13 | int sum = 0; 14 | 15 | if (up >= 'A'&&up <= 'Z') 16 | { 17 | low = up - 'A' + 'a'; 18 | } 19 | else 20 | { 21 | low = up; 22 | up = up - 'a' + 'A'; 23 | } 24 | 25 | for (int i = 0;i 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | const string helper1 = "0123456789abcdefABCDEF"; 14 | const string helper2 = "084C2A6E195D3B7F5D3B7F"; 15 | 16 | int test_30() { 17 | string str1, str2; 18 | while (cin >> str1 >> str2) { 19 | string s, s1, s2; 20 | s = str1 + str2; 21 | int len = s.size(); 22 | for (int i = 0; i < len; ++i) { 23 | if (i % 2 == 0) 24 | s1 += s[i]; 25 | else 26 | s2 += s[i]; 27 | } 28 | sort(s1.begin(), s1.end()); 29 | sort(s2.begin(), s2.end()); 30 | s.clear(); 31 | for (int i = 0, j = 0, k = 0; i < len; ++i) { 32 | if (i % 2 == 0) 33 | s += s1[j++]; 34 | else 35 | s += s2[k++]; 36 | } 37 | for (int i = 0; i < len; ++i) { 38 | int n = helper1.find(s[i]); 39 | if (n != -1) 40 | s[i] = helper2[n]; 41 | } 42 | cout << s << endl; 43 | } 44 | return 0; 45 | } -------------------------------------------------------------------------------- /HuaWei/31单词倒排.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | int test_31() 14 | { 15 | string str; 16 | while (getline(cin, str)) 17 | { 18 | vector juzi; 19 | for (int i = 0;i= 0;i--) 39 | { 40 | if (i>0) 41 | cout << juzi[i] << " "; 42 | if (i == 0) 43 | cout << juzi[i] << endl; 44 | } 45 | 46 | } 47 | return 0; 48 | } -------------------------------------------------------------------------------- /HuaWei/32字符串运用-密码截取.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | using namespace std; 6 | 7 | int test_32() 8 | { 9 | string str; 10 | while (cin >> str) 11 | { 12 | string newstr; 13 | for (int i = 0;i= 0 && 24 | i + count <= newstr.size() && 25 | newstr[i - count] == newstr[i + count] 26 | ) 27 | { 28 | count++; 29 | } 30 | if (count - 1>max) 31 | { 32 | max = count - 1; 33 | } 34 | } 35 | cout << max << endl; 36 | } 37 | return 0; 38 | } -------------------------------------------------------------------------------- /HuaWei/33整数与IP地址间的转换.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | using namespace std; 5 | 6 | int test_33() 7 | { 8 | long long n, a1, a2, a3, a4; 9 | char ch; 10 | while (cin >> a1 >> ch >> a2 >> ch >> a3 >> ch >> a4) 11 | { 12 | cin >> n; 13 | long long inter = (a1 << 24) + (a2 << 16) + (a3 << 8) + a4; 14 | a1 = n >> 24; 15 | a2 = (n >> 16) & 255; 16 | a3 = (n >> 8) & 255; 17 | a4 = n & 255; 18 | cout << inter << endl; 19 | cout << a1 << "." << a2 << "." << a3 << "." << a4 << endl; 20 | } 21 | return 0; 22 | } -------------------------------------------------------------------------------- /HuaWei/34图片整理.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int test_34() 9 | { 10 | string data; 11 | while (cin >> data) 12 | { 13 | sort(data.begin(), data.end()); 14 | cout << data << endl; 15 | } 16 | return 0; 17 | } -------------------------------------------------------------------------------- /HuaWei/35蛇形矩阵.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | using namespace std; 5 | 6 | int test_35() 7 | { 8 | int Num; 9 | while (cin >> Num) 10 | { 11 | int head = 1; 12 | for (int i = 0; i 4 | using namespace std; 5 | 6 | int test_38() 7 | { 8 | int number; 9 | while (cin >> number) 10 | { 11 | cout << 2.875 * number << endl; 12 | cout << 0.03125 * number << endl; 13 | } 14 | return 0; 15 | } -------------------------------------------------------------------------------- /HuaWei/39判断两个IP是否属于同一子网.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" -------------------------------------------------------------------------------- /HuaWei/3明明的随机数.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int test_3() 9 | { 10 | int num = 0; 11 | while (cin >> num) 12 | { 13 | int value; 14 | set iset; 15 | for (int i = 0; i> value; 18 | iset.insert(value); 19 | } 20 | for (auto m = iset.begin();m != iset.end();m++) 21 | { 22 | cout << *m << endl; 23 | } 24 | } 25 | return 0; 26 | } -------------------------------------------------------------------------------- /HuaWei/40输入一行字符,分别统计出包含英文字母空格数字和其它字符的个数.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | int test_40() 10 | { 11 | string str; 12 | while (getline(cin, str)) 13 | { 14 | int English = 0, Blank = 0, Number = 0, Other = 0; 15 | for (int i = 0;i helper1{ "","thousand", "million", "billion" }; 4 | vector helper2{ 5 | "", "", "twenty", "thirty", "forty", 6 | "fifty","sixty","seventy","eighty","ninety" }; 7 | vector helper3{ 8 | "", "one", "two", "three", "four","five", 9 | "six","seven","eight","nine" }; 10 | vector helper4{ 11 | "ten", "eleven", "twelve", "thirteen", "fourteen", 12 | "fifteen","sixteen","seventeen","eighteen","nineteen" }; 13 | 14 | string sound(int num) 15 | { 16 | string res; 17 | if (num >= 0 && num <= 9) 18 | res += helper3[num]; 19 | else if (num >= 10 && num <= 19) 20 | res += helper4[num % 10]; 21 | else if (num >= 20 && num <= 99) 22 | { 23 | res += helper2[num / 10]; 24 | if (num % 10 != 0) 25 | { 26 | res += " "; 27 | res += helper3[num % 10]; 28 | } 29 | } 30 | else 31 | { 32 | res += helper3[num / 100]; 33 | res += " hundred"; 34 | num %= 100; 35 | if (num) { 36 | res += " and "; 37 | res += sound(num); 38 | } 39 | } 40 | return res; 41 | } 42 | 43 | int test_42() 44 | { 45 | long num; 46 | while (cin >> num) 47 | { 48 | vector parts; 49 | string res; 50 | if (num == 0) 51 | { 52 | cout << "zero" << endl; 53 | continue; 54 | } 55 | else if (num > 999999999 || num < 0) 56 | { 57 | cout << "error" << endl; 58 | continue; 59 | } 60 | while (num != 0) 61 | { 62 | int tmp = num % 1000; 63 | parts.push_back(tmp);//1-1thousand,1t-1m,1m-1b 64 | num /= 1000; 65 | } 66 | 67 | for (int i = parts.size() - 1; i >= 0; i--) 68 | { 69 | string tmp = sound(parts[i]); 70 | if (tmp == "") 71 | continue; 72 | res += tmp; 73 | if (i) 74 | { 75 | res += " "; 76 | res += helper1[i]; 77 | res += " "; 78 | } 79 | } 80 | while (res[res.size() - 1] == ' ') res.erase(res.end() - 1); 81 | cout << res << endl; 82 | } 83 | return 0; 84 | } -------------------------------------------------------------------------------- /HuaWei/43迷宫问题.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/43迷宫问题.cpp -------------------------------------------------------------------------------- /HuaWei/44Sudoku.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/44Sudoku.cpp -------------------------------------------------------------------------------- /HuaWei/45名字的漂亮度.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/45名字的漂亮度.cpp -------------------------------------------------------------------------------- /HuaWei/46按字节截取字符串.cpp: -------------------------------------------------------------------------------- 1 | #include"stdafx.h" 2 | 3 | int test_46() 4 | { 5 | string str; 6 | int maxsize; 7 | while (cin >> str >> maxsize) 8 | { 9 | int realmax = 0; 10 | for (int i = 0;i127) 13 | { 14 | realmax += 2; 15 | } 16 | else 17 | { 18 | realmax += 1; 19 | } 20 | if (realmax>maxsize) 21 | { 22 | realmax -= 2; 23 | break; 24 | } 25 | } 26 | str = str.substr(0, realmax); 27 | cout << str; 28 | cout << endl; 29 | } 30 | return 0; 31 | } -------------------------------------------------------------------------------- /HuaWei/47线性插值.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/47线性插值.cpp -------------------------------------------------------------------------------- /HuaWei/48从单向链表中删除指定值的节点.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/48从单向链表中删除指定值的节点.cpp -------------------------------------------------------------------------------- /HuaWei/49多线程.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/49多线程.cpp -------------------------------------------------------------------------------- /HuaWei/4字符串分隔.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | void str_handler(string& s) { 9 | if (s.size() <= 8) 10 | { 11 | s.append(8 - s.size(), '0'); 12 | cout << s << endl; 13 | } 14 | else 15 | { 16 | cout << s.substr(0, 8) << endl; 17 | string s1 = s.substr(8, s.size() - 8); 18 | str_handler(s1); 19 | } 20 | } 21 | 22 | int test_4() 23 | { 24 | string s1, s2; 25 | while (cin >> s1 >> s2) { 26 | str_handler(s1); 27 | str_handler(s2); 28 | } 29 | return 0; 30 | } -------------------------------------------------------------------------------- /HuaWei/50四则运算.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/50四则运算.cpp -------------------------------------------------------------------------------- /HuaWei/5进制转换.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/5进制转换.cpp -------------------------------------------------------------------------------- /HuaWei/6质数因子.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | int test_6() 10 | { 11 | long data; 12 | while (cin >> data) 13 | { 14 | string ret; 15 | long tmp = data; 16 | while (tmp != 1) 17 | { 18 | for (int i = 2;i <= tmp;i++) 19 | { 20 | if (tmp%i == 0) 21 | { 22 | ret += to_string(i); 23 | ret += " "; 24 | tmp /= i; 25 | break; 26 | } 27 | } 28 | } 29 | cout << ret << endl; 30 | } 31 | return 0; 32 | } -------------------------------------------------------------------------------- /HuaWei/7取近似值.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | int test_7() 11 | { 12 | double value; 13 | while (cin >> value) 14 | { 15 | value += 0.5; 16 | cout << floor(value) << endl; 17 | } 18 | return 0; 19 | } -------------------------------------------------------------------------------- /HuaWei/8合并表记录.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | using namespace std; 10 | 11 | int test_8() 12 | { 13 | int n; 14 | while (cin >> n) 15 | { 16 | int iKey, iValue; 17 | map mMap; 18 | for (int i = 0;i> iKey >> iValue; 21 | mMap[iKey] += iValue; 22 | } 23 | for (auto i = mMap.begin();i != mMap.end();++i) 24 | { 25 | cout << i->first << " " << i->second << endl; 26 | } 27 | } 28 | return 0; 29 | } -------------------------------------------------------------------------------- /HuaWei/9提取不重复的整数.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/9提取不重复的整数.cpp -------------------------------------------------------------------------------- /HuaWei/HuaWei.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/HuaWei.cpp -------------------------------------------------------------------------------- /HuaWei/HuaWei.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/HuaWei.h -------------------------------------------------------------------------------- /HuaWei/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:HuaWei 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 HuaWei 应用程序。 6 | 7 | 本文件概要介绍组成 HuaWei 应用程序的每个文件的内容。 8 | 9 | 10 | HuaWei.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | HuaWei.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | HuaWei.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 HuaWei.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /HuaWei/a清一色.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/a清一色.cpp -------------------------------------------------------------------------------- /HuaWei/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/stdafx.cpp -------------------------------------------------------------------------------- /HuaWei/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/stdafx.h -------------------------------------------------------------------------------- /HuaWei/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/targetver.h -------------------------------------------------------------------------------- /HuaWei/成绩排序.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/成绩排序.cpp -------------------------------------------------------------------------------- /HuaWei/找出字符串中第一个只出现一次的字符.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/HuaWei/找出字符串中第一个只出现一次的字符.cpp -------------------------------------------------------------------------------- /HuaWei/火车进站.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "HuaWei.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | bool isOutNum(int *push, int *pop, int len)//判断pop是不是push的出栈序列 10 | { 11 | if (push == NULL || pop == NULL || len <= 0) 12 | return false; 13 | stack Stack; 14 | int i = 0, j = 0; 15 | for (i = 0;i> N) 31 | { 32 | int *pushNum = new int[N]; 33 | int *popNum = new int[N]; 34 | for (int i = 0;i> pushNum[i]; 37 | popNum[i] = pushNum[i]; 38 | } 39 | sort(popNum, popNum + N); 40 | 41 | vector vec(N); 42 | for (size_t i = 0; i < vec.size(); i++) 43 | { 44 | vec[i] = popNum[i]; 45 | } 46 | 47 | do 48 | { 49 | if (isOutNum(pushNum, popNum, N))//如果该排列正确,则输出 50 | { 51 | for (int i = 0;i 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeCSharp/FormMain.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace LeetCode 2 | { 3 | partial class FormMain 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.btnStart = new System.Windows.Forms.Button(); 32 | this.txtNum = new System.Windows.Forms.TextBox(); 33 | this.txtOut = new System.Windows.Forms.TextBox(); 34 | this.题号 = new System.Windows.Forms.Label(); 35 | this.SuspendLayout(); 36 | // 37 | // btnStart 38 | // 39 | this.btnStart.Location = new System.Drawing.Point(57, 80); 40 | this.btnStart.Name = "btnStart"; 41 | this.btnStart.Size = new System.Drawing.Size(75, 23); 42 | this.btnStart.TabIndex = 0; 43 | this.btnStart.Text = "Start"; 44 | this.btnStart.UseVisualStyleBackColor = true; 45 | this.btnStart.Click += new System.EventHandler(this.btnStart_Click); 46 | // 47 | // txtNum 48 | // 49 | this.txtNum.Location = new System.Drawing.Point(90, 27); 50 | this.txtNum.Name = "txtNum"; 51 | this.txtNum.Size = new System.Drawing.Size(100, 25); 52 | this.txtNum.TabIndex = 1; 53 | // 54 | // txtOut 55 | // 56 | this.txtOut.Location = new System.Drawing.Point(282, 27); 57 | this.txtOut.Multiline = true; 58 | this.txtOut.Name = "txtOut"; 59 | this.txtOut.Size = new System.Drawing.Size(521, 321); 60 | this.txtOut.TabIndex = 2; 61 | // 62 | // 题号 63 | // 64 | this.题号.AutoSize = true; 65 | this.题号.Location = new System.Drawing.Point(29, 30); 66 | this.题号.Name = "题号"; 67 | this.题号.Size = new System.Drawing.Size(55, 15); 68 | this.题号.TabIndex = 3; 69 | this.题号.Text = "label1"; 70 | // 71 | // FormMain 72 | // 73 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); 74 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 75 | this.ClientSize = new System.Drawing.Size(815, 369); 76 | this.Controls.Add(this.题号); 77 | this.Controls.Add(this.txtOut); 78 | this.Controls.Add(this.txtNum); 79 | this.Controls.Add(this.btnStart); 80 | this.Name = "FormMain"; 81 | this.Text = "FormMain"; 82 | this.ResumeLayout(false); 83 | this.PerformLayout(); 84 | 85 | } 86 | 87 | #endregion 88 | 89 | private System.Windows.Forms.Button btnStart; 90 | private System.Windows.Forms.TextBox txtNum; 91 | private System.Windows.Forms.TextBox txtOut; 92 | private System.Windows.Forms.Label 题号; 93 | } 94 | } -------------------------------------------------------------------------------- /LeetCode/LeetCodeCSharp/FormMain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | using LeetCode.算法; 11 | 12 | namespace LeetCode 13 | { 14 | public partial class FormMain : Form 15 | { 16 | public FormMain() 17 | { 18 | InitializeComponent(); 19 | } 20 | 21 | private void btnStart_Click(object sender, EventArgs e) 22 | { 23 | int num = Convert.ToInt32(txtNum.Text); 24 | _709 t_709 = new _709(); 25 | var ret_709 = t_709.ToLowerCase("PiTAs"); 26 | string output = ret_709.ToString(); 27 | txtOut.Text = output; 28 | } 29 | 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeCSharp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace LeetCode 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// 应用程序的主入口点。 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new FormMain()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeCSharp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("LeetCode")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("LeetCode")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | //将 ComVisible 设置为 false 将使此程序集中的类型 18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("ff2c8c81-083c-459f-9443-1024483a5433")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeCSharp/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本: 4.0.30319.42000 5 | // 6 | // 对此文件的更改可能导致不正确的行为,如果 7 | // 重新生成代码,则所做更改将丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace LeetCode.Properties 12 | { 13 | 14 | 15 | /// 16 | /// 强类型资源类,用于查找本地化字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// 返回此类使用的缓存 ResourceManager 实例。 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("LeetCode.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// 覆盖当前线程的 CurrentUICulture 属性 56 | /// 使用此强类型的资源类的资源查找。 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeCSharp/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace LeetCode.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeCSharp/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeCSharp/算法/155.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LeetCode.算法 8 | { 9 | public class MinStack 10 | { 11 | private readonly Stack data = new Stack(); 12 | private readonly Stack minValue = new Stack(); 13 | 14 | /** initialize your data structure here. */ 15 | public MinStack() 16 | { 17 | 18 | } 19 | 20 | public void Push(int x) 21 | { 22 | data.Push(x); 23 | if (minValue.Count == 0 || x <= minValue.Peek()) 24 | minValue.Push(x); 25 | } 26 | 27 | public void Pop() 28 | { 29 | int value = data.Pop(); 30 | if (value == minValue.Peek()) 31 | minValue.Pop(); 32 | } 33 | 34 | public int Top() 35 | { 36 | return data.Peek(); 37 | } 38 | 39 | public int GetMin() 40 | { 41 | return minValue.Peek(); 42 | } 43 | } 44 | 45 | public class MinStackTest 46 | { 47 | static void test() 48 | { 49 | MinStack obj = new MinStack(); 50 | obj.Push(5); 51 | obj.Pop(); 52 | int param_3 = obj.Top(); 53 | int param_4 = obj.GetMin(); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeCSharp/算法/535.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LeetCode.算法 8 | { 9 | /// 10 | /// TinyURL 的加密与解密 11 | /// 12 | /// 13 | /// 短链接URL系统是怎么设计的? 14 | /// http://www.codeceo.com/article/short-url-system-design.html 15 | /// TinyURL的实现原理 16 | /// https://blog.csdn.net/bdss58/article/details/74784428 17 | /// leetcode 535. Encode and Decode TinyURL(长短网址互译) 18 | /// https://blog.csdn.net/a731604348/article/details/70150107 19 | /// 20 | class _535 21 | { 22 | private static string BASE_HOST = "http://tinyurl.com/"; 23 | private static string SEED = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; 24 | 25 | private Dictionary keyToUrl = new Dictionary(); 26 | private Dictionary urlToKey = new Dictionary(); 27 | // Encodes a URL to a shortened URL 28 | public string encode(string longUrl) 29 | { 30 | if (urlToKey.ContainsKey(longUrl)) 31 | { 32 | return BASE_HOST + urlToKey[longUrl]; 33 | } 34 | 35 | string key = null; 36 | do 37 | { 38 | StringBuilder sb = new StringBuilder(); 39 | for (int i = 0; i < 6; i++) 40 | { 41 | int r = (int)(new Random().Next(SEED.Length)); 42 | sb.Append(SEED.ElementAt(r)); 43 | } 44 | key = sb.ToString(); 45 | } while (keyToUrl.ContainsKey(key)); 46 | 47 | keyToUrl.Add(key, longUrl); 48 | urlToKey.Add(longUrl, key); 49 | return BASE_HOST + key; 50 | } 51 | 52 | // Decodes a shortened URL to its original URL. 53 | public string decode(string shortUrl) 54 | { 55 | return keyToUrl[shortUrl.Replace(BASE_HOST, "")]; 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeCSharp/算法/657.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LeetCode.算法 8 | { 9 | class _657 10 | { 11 | public bool JudgeCircle(string moves) 12 | { 13 | int lr = moves.Count(c => c == 'L') - moves.Count(c => c == 'R'); 14 | int ud = moves.Count(c => c == 'U') - moves.Count(c => c == 'D'); 15 | if (lr==0&&ud==0) 16 | { 17 | return true; 18 | } 19 | return false; 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeCSharp/算法/709.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LeetCode.算法 8 | { 9 | public class _709 10 | { 11 | public string ToLowerCase(string str) 12 | { 13 | string strtmp = ""; 14 | for (int i = 0; i < str.Length; i++) 15 | { 16 | if (str[i] >= 'A' && str[i] <= 'Z') 17 | { 18 | var itmp = str[i] - 'A' + 'a'; 19 | strtmp += Convert.ToChar(itmp); 20 | } 21 | else 22 | { 23 | strtmp += str[i]; 24 | } 25 | } 26 | return strtmp; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeCSharp/算法/804.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LeetCode.算法 8 | { 9 | class _804 10 | { 11 | string[] Morse = { 12 | ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", 13 | "....", "..", ".---", "-.-", ".-..", "--", "-.", 14 | "---", ".--.", "--.-", ".-.", "...", "-", 15 | "..-", "...-", ".--", "-..-", "-.--", "--.." 16 | }; 17 | 18 | /// 19 | /// 20 | /// 21 | /// 22 | /// 23 | /// 24 | /// 例如: 25 | /// 输入: words = ["gin", "zen", "gig", "msg"] 26 | /// 输出: 2 27 | /// 解释: 28 | /// 各单词翻译如下: 29 | /// "gin" -> "--...-." 30 | /// "zen" -> "--...-." 31 | /// "gig" -> "--...--." 32 | /// "msg" -> "--...--." 33 | /// 34 | /// 共有 2 种不同翻译, "--...-." 和 "--...--.". 35 | /// 36 | public int UniqueMorseRepresentations(string[] words) 37 | { 38 | List m = new List(); 39 | for (int i = 0; i < words.Length; i++) 40 | { 41 | string tmp = Transfer2Morse(words[i]); 42 | if (!m.Contains(tmp)) 43 | { 44 | m.Add(tmp); 45 | } 46 | } 47 | return m.Count; 48 | } 49 | 50 | public string Transfer2Morse(string word) 51 | { 52 | string ret = ""; 53 | for (int i = 0; i < word.Length; i++) 54 | { 55 | int num = Convert.ToInt32(word.ElementAt(i)) - 97; 56 | ret += Morse[num]; 57 | } 58 | return ret; 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /LeetCode/LeetCodeCSharp/算法/852.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LeetCode.算法 8 | { 9 | class _852 10 | { 11 | /// 12 | /// 13 | /// 14 | /// 15 | /// 16 | /// 17 | /// a) 3 <= A.length <= 10000 18 | /// b) 0 <= A[i] <= 10^6 19 | /// c) 存在 0 < i < A.length - 1 使得 20 | /// A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1] 21 | /// title: 给定一个确定为山脉的数组,返回任何满足 22 | /// A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1] 的 i 的值。 23 | /// 24 | public int PeakIndexInMountainArray(int[] A) 25 | { 26 | int pos = 0; 27 | for (int i = 1; i < A.Length; i++) 28 | { 29 | if (A[i]>A[i-1]) 30 | { 31 | pos = i; 32 | } 33 | } 34 | return pos; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeCSharp/算法/867.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace LeetCode.算法 8 | { 9 | public class Solution 10 | { 11 | public int[][] Transpose(int[][] A) 12 | { 13 | int raw = A.Length; 14 | int column = A[0].Length; 15 | int[][] ret = new int[column][]; 16 | for (int j = 0; j < column; j++) 17 | { 18 | ret[j] = new int[raw]; 19 | } 20 | for (int i = 0; i < raw; i++) 21 | { 22 | for (int j = 0; j < column; j++) 23 | { 24 | ret[j][i] = A[i][j]; 25 | } 26 | } 27 | return ret; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/1.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/101对称二叉树.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/101对称二叉树.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/102二叉树的层次遍历.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/102二叉树的层次遍历.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/104.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/104.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/108将有序数组转换为二叉搜索树.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/108将有序数组转换为二叉搜索树.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/111二叉树的最小深度.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/111二叉树的最小深度.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/121.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/121.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/122.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/122.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/125.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/125.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/128.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/128.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/132分隔回文串.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | /* 3 | 给定一个字符串 s,将 s 分割成一些子串,使每个子串都是回文串。 4 | 5 | 返回符合要求的最少分割次数。 6 | 7 | 示例: 8 | 9 | 输入: "aab" 10 | 输出: 1 11 | 解释: 进行一次分割就可将 s 分割成 ["aa","b"] 这样两个回文子串。 12 | 13 | */ 14 | /* 15 | java版参考 16 | public class Solution { 17 | public int minCut(String s) { 18 | int n = s.length(); 19 | boolean[][] judge = new boolean[n][n]; 20 | int[] dp = new int[n]; // dp[i]表示s中第i个字符到第(n-1)个字符所构成的子串的最小分割次数 21 | for (int i = n - 1; i >= 0; i--) { 22 | dp[i] = Integer.MAX_VALUE; 23 | for (int j = i; j < n; j++) { 24 | if (s.charAt(i) == s.charAt(j) && (j - i <= 1 || judge[i + 1][j - 1])) { 25 | judge[i][j] = true; 26 | if (j + 1 < n) { 27 | dp[i] = Math.min(dp[i], 1 + dp[j + 1]); 28 | } else { 29 | dp[i] = 0; 30 | } 31 | } 32 | } 33 | } 34 | return dp[0]; 35 | } 36 | } 37 | 38 | */ 39 | 40 | class Solution { 41 | public: 42 | int minCut(string s) 43 | { 44 | vector> dp; 45 | vector temp; 46 | for (int i = 0;i cut(s.size() + 1, 0); 53 | 54 | for (int i = s.size() - 1;i >= 0;i--) 55 | { 56 | cut[i] = INT_MAX; 57 | for (int j = i;j 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | /* 11 | 给定一个整数数组,判断数组中是否有两个不同的索引 i 和 j,使得 nums [i] 和 nums [j] 的差的绝对值最大为 t,并且 i 和 j 之间的差的绝对值最大为 ķ。 12 | 13 | 示例 1: 14 | 15 | 输入: nums = [1,2,3,1], k = 3, t = 0 16 | 输出: true 17 | 示例 2: 18 | 19 | 输入: nums = [1,0,1,1], k = 1, t = 2 20 | 输出: true 21 | 示例 3: 22 | 23 | 输入: nums = [1,5,9,1,5,9], k = 2, t = 3 24 | 输出: false 25 | */ 26 | 27 | /* 28 | s思路: 29 | 1. 看了提示,用binary search tree。用BST,在c++就是用set或map了, 30 | 因为这两样就是用bst实现的。 31 | 32 | 2. 因为没有重复,所以不能用hash。坐标之差在一个范围内,我们可以 33 | 每次只在这个范围内寻找数,比如:从左往右移动,当长度大于k,那么 34 | 就把搜索区间的最左边删除,类似与two pointer的方法,只是这个窗口 35 | 达到k后就不增加了; 36 | 37 | 3. 数据之差如何搞定呢?当然可以在窗口内双重循环找到所有数据之差 38 | 然后判断是否存在一个数据差小于t,但这样复杂度就是o(k^2),由于没窗 39 | 口每次移动一下,都要这样来一遍,所以总的复杂度o(nk^2),还是太大。 40 | 41 | 4. 主要的问题是:在k长的窗口内,是否存在|nums[i]-nums[j]|<=t的一对 42 | 数据?由于数据是无序的,难道一定要遍历所有o(k^2)的可能吗?这几天都 43 | 在说,要从无序中看出是否有序的可能,先不说马上能看到,但一定要有 44 | 信念,不然真看不到,因为心里着急,气急败坏,没有信心嘛。 45 | 46 | 5. 先把上面的不等式展开:-t<=nums[i]-nums[j]<=t,继续处理: 47 | 48 | nums[i]-t<=nums[j]<=nums[i]+t 49 | 50 | 注意看,这就和原来不一样了,我们假设i是从左往右遍历的当前的数的index 51 | */ 52 | class Solution { 53 | public: 54 | bool containsNearbyAlmostDuplicate(vector& nums, int k, int t) { 55 | if (k<1 || t<0) return false; 56 | 57 | set ss;//bug:调试很久,刚开始用int,发现要做运算,极限case过不了,所以用long保护 58 | long lt = t; 59 | 60 | for (int i = 0;ik) 64 | ss.erase(nums[i - k - 1]); 65 | //取nums[i]-t<=nums[j] 66 | //bug:只需要把其中之一转换成long即可 67 | set::iterator it = ss.lower_bound(nums[i] - lt); 68 | //判断是否有nums[i]-t<=nums[j]<=nums[i]+t 69 | //*it即nums[j] 70 | if (it != ss.end() && (*it) - nums[i] <= t) 71 | return true; 72 | //没有则将nums[j]加入窗口中 73 | ss.insert(nums[i]); 74 | } 75 | return false; 76 | } 77 | }; 78 | 79 | bool test_220(vector vec,int k,int t) 80 | { 81 | Solution s; 82 | auto ret = s.containsNearbyAlmostDuplicate(vec, k, t);//true 83 | return ret; 84 | } -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/226翻转二叉树.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/226翻转二叉树.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/231.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | bool isPowerOfTwo(int n) { 8 | if (n <= 0) return false; 9 | if ((n&(n - 1)) == 0) return true; 10 | return false; 11 | } 12 | }; -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/234.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/234.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/237删除链表中的节点.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/237删除链表中的节点.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/242.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/242.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/278.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/278.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/28.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/28.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/283.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/283.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/3.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/3.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/326.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/326.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/338.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/338.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/342.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/342.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/344.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/344.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/349.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/349.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/350.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/350.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/38.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | class Solution { 11 | public: 12 | string getNext(string s) 13 | { 14 | string result; 15 | int i = 0; 16 | int count; 17 | while (i < s.size()) 18 | { 19 | count = 1; 20 | char temp; 21 | if (s[i] == s[i + 1]) 22 | { 23 | while (s[i] == s[i + 1]) 24 | { 25 | count++; 26 | i++; 27 | } 28 | temp = count + '0'; 29 | result = result + temp + s[i]; 30 | i++; 31 | } 32 | else 33 | { 34 | temp = '1'; 35 | result = result + temp + s[i]; 36 | i++; 37 | } 38 | } 39 | return result; 40 | } 41 | 42 | string countAndSay(int n) { 43 | if (n == 1) 44 | return "1"; 45 | string s = "1"; 46 | while (--n) 47 | { 48 | s = getNext(s); 49 | } 50 | return s; 51 | 52 | } 53 | }; -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/384打乱数组.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/384打乱数组.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/387.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/387.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/44.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/44.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/46.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/46.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/461.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Solution { 7 | public: 8 | int hammingDistance(int x, int y) { 9 | int tmp = x^y; 10 | int sum = 0; 11 | while (tmp != 0) 12 | { 13 | if (tmp & 1 != 0) 14 | { 15 | sum++; 16 | } 17 | tmp = tmp >> 1; 18 | } 19 | return sum; 20 | } 21 | }; -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/476.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/476.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/48.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/48.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/53.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/53.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/537.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "LeetCodeCppTest.h" 9 | using namespace std; 10 | 11 | class Solution { 12 | public: 13 | int GetReal(string& str,int plus) 14 | { 15 | string ret = str.substr(0, plus); 16 | return stoi(ret); 17 | } 18 | 19 | int GetImaginary(string& str, int plus) 20 | { 21 | string ret = str.substr(plus+1, str.size() - plus - 2); 22 | return stoi(ret); 23 | } 24 | 25 | string complexNumberMultiply(string a, string b) { 26 | int tmp = a.find("+"); 27 | int realA = GetReal(a, tmp); 28 | int imaginaryA = GetImaginary(a, tmp); 29 | tmp = b.find("+"); 30 | int realB = GetReal(b, tmp); 31 | int imaginaryB = GetImaginary(b, tmp); 32 | 33 | int real = realA*realB+ imaginaryA*imaginaryB*(-1); 34 | int imaginary = realA*imaginaryB + realB*imaginaryA; 35 | return to_string(real) + "+" + to_string(imaginary) + "i"; 36 | } 37 | 38 | }; 39 | 40 | int test_537() 41 | { 42 | Solution s; 43 | s.complexNumberMultiply("20+22i", "-18+-10i"); 44 | return 0; 45 | } -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/617合并二叉树.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/617合并二叉树.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/654最大二叉树.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/654最大二叉树.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/657.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | class Solution { 10 | public: 11 | bool judgeCircle(string moves) { 12 | int lr = 0, ud = 0; 13 | for (size_t i = 0; i < moves.size(); i++) 14 | { 15 | switch (moves[i]) 16 | { 17 | case 'L': 18 | lr--; 19 | break; 20 | case 'R': 21 | lr++; 22 | break; 23 | case 'U': 24 | ud++; 25 | break; 26 | case 'D': 27 | ud--; 28 | break; 29 | default: 30 | break; 31 | } 32 | } 33 | if (lr==0&&ud==0) 34 | { 35 | return true; 36 | } 37 | return false; 38 | } 39 | }; -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/7.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | /* 4 | 给定一个 32 位有符号整数,将整数中的数字进行反转。 5 | 6 | 示例 1: 7 | 8 | 输入: 123 9 | 输出: 321 10 | 示例 2: 11 | 12 | 输入: -123 13 | 输出: -321 14 | 示例 3: 15 | 16 | 输入: 120 17 | 输出: 21 18 | 注意: 19 | 20 | 假设我们的环境只能存储 32 位有符号整数,其数值范围是 [−231, 231 − 1]。根据这个假设,如果反转后的整数溢出,则返回 0。 21 | */ 22 | class Solution { 23 | public: 24 | int reverse(int x) { 25 | int ret = 0; 26 | int flag = 1; 27 | if (x<0) flag = -1; 28 | 29 | while (x != 0) 30 | { 31 | if (ret>INT_MAX / 10) return 0; 32 | if (ret 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | class Solution { 9 | public: 10 | string toLowerCase(string str) { 11 | for (size_t i = 0; i < str.length(); i++) 12 | { 13 | if (str[i] >= 'A'&&str[i] <= 'Z') 14 | { 15 | char tmp = str[i] - 'A' + 'a'; 16 | //•用str中的num2个字符(从index2开始)替换本字符串中的字符,从index1开始,num1个字符 17 | //_Myt& replace(size_type _Off,size_type _N0, size_type _Count, _Elem _Ch) 18 | //replace [_Off, _Off + _N0) with _Count * _Ch 19 | str.replace(i, 1, 1, tmp); 20 | } 21 | } 22 | return str; 23 | } 24 | }; 25 | 26 | int test_709() 27 | { 28 | Solution s; 29 | string str("ZzPiTAs"); 30 | cout << str.c_str() << endl; 31 | str = s.toLowerCase(str); 32 | cout << str.c_str() << endl; 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/728.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/728.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/78.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/78.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/8.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | using namespace std; 9 | 10 | /* 11 | 实现 atoi,将字符串转为整数。 12 | 13 | 在找到第一个非空字符之前,需要移除掉字符串中的空格字符。如果第一个非空字符是正号或负号,选取该符号,并将其与后面尽可能多的连续的数字组合起来,这部分字符即为整数的值。如果第一个非空字符是数字,则直接将其与之后连续的数字字符组合起来,形成整数。 14 | 15 | 字符串可以在形成整数的字符后面包括多余的字符,这些字符可以被忽略,它们对于函数没有影响。 16 | 17 | 当字符串中的第一个非空字符序列不是个有效的整数;或字符串为空;或字符串仅包含空白字符时,则不进行转换。 18 | 19 | 若函数不能执行有效的转换,返回 0。 20 | 21 | 说明: 22 | 23 | 假设我们的环境只能存储 32 位有符号整数,其数值范围是 [−231, 231 − 1]。如果数值超过可表示的范围,则返回 INT_MAX (231 − 1) 或 INT_MIN (−231) 。 24 | 25 | 示例 1: 26 | 27 | 输入: "42" 28 | 输出: 42 29 | 示例 2: 30 | 31 | 输入: " -42" 32 | 输出: -42 33 | 解释: 第一个非空白字符为 '-', 它是一个负号。 34 | 我们尽可能将负号与后面所有连续出现的数字组合起来,最后得到 -42 。 35 | 示例 3: 36 | 37 | 输入: "4193 with words" 38 | 输出: 4193 39 | 解释: 转换截止于数字 '3' ,因为它的下一个字符不为数字。 40 | 示例 4: 41 | 42 | 输入: "words and 987" 43 | 输出: 0 44 | 解释: 第一个非空字符是 'w', 但它不是数字或正、负号。 45 | 因此无法执行有效的转换。 46 | 示例 5: 47 | 48 | 输入: "-91283472332" 49 | 输出: -2147483648 50 | 解释: 数字 "-91283472332" 超过 32 位有符号整数范围。 51 | 因此返回 INT_MIN (−231) 。 52 | */ 53 | class Solution { 54 | public: 55 | int myAtoi(string str) { 56 | if (str.empty()) return 0; 57 | int sign = 1, base = 0, i = 0, n = str.size(); 58 | while (i < n && str[i] == ' ') ++i; 59 | if (str[i] == '+' || str[i] == '-') { 60 | sign = (str[i++] == '+') ? 1 : -1; 61 | } 62 | while (i < n && str[i] >= '0' && str[i] <= '9') { 63 | if (base > INT_MAX / 10 || (base == INT_MAX / 10 && str[i] - '0' > 7)) { 64 | return (sign == 1) ? INT_MAX : INT_MIN; 65 | } 66 | base = 10 * base + (str[i++] - '0'); 67 | } 68 | return base * sign; 69 | } 70 | }; 71 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/814二叉树剪枝.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/814二叉树剪枝.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/832.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | void swap(int& a, int& b) 8 | { 9 | int temp = a; 10 | a = b; 11 | b = temp; 12 | } 13 | 14 | vector> flipImage(vector>& A) { 15 | size_t raw = A.size(); 16 | size_t column = A[0].size(); 17 | 18 | for (size_t i = 0; i < raw; i++) 19 | { 20 | for (size_t j = 0; j < column/2; j++) 21 | { 22 | swap(A[i][j], A[i][column-j-1]); 23 | } 24 | } 25 | 26 | return A; 27 | } 28 | 29 | vector> InvertImage(vector>& A) { 30 | size_t raw = A.size(); 31 | size_t column = A[0].size(); 32 | 33 | for (size_t i = 0; i < raw; i++) 34 | { 35 | for (size_t j = 0; j < column; j++) 36 | { 37 | A[i][j] = 1 - A[i][j]; 38 | } 39 | } 40 | 41 | return A; 42 | } 43 | 44 | vector> flipAndInvertImage(vector>& A) { 45 | size_t raw = A.size(); 46 | size_t column = A[0].size(); 47 | 48 | flipImage(A); 49 | InvertImage(A); 50 | return A; 51 | } 52 | }; -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/846.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Solution { 7 | public: 8 | bool isNStraightHand(vector& hand, int W) { 9 | if (0 != hand.size() % W) 10 | { 11 | return false; 12 | } 13 | 14 | sort(hand.begin(), hand.end()); 15 | 16 | vector::iterator it = hand.begin(); 17 | int len = hand.size() / W; 18 | for (size_t i = 0; i < len; i++) 19 | { 20 | int start = hand[0]; 21 | int cnt = 0; 22 | it = hand.begin(); 23 | while (cnt 6 | using namespace std; 7 | 8 | vector test_1(vector& nums, int target); 9 | bool test_44(string s, string p); 10 | int test_122(); 11 | bool test_220(vector vec, int k, int t); 12 | bool test_234(int arr[], int size); 13 | int test_278(int n); 14 | int test_537(); 15 | int test_387(string s); 16 | #endif // !_LEETCODECPP_H_ 17 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/ListNode.h: -------------------------------------------------------------------------------- 1 | #ifndef _LISTNODE_H_ 2 | #define _LISTNODE_H_ 3 | #include 4 | 5 | /** 6 | * Definition for singly-linked list. 7 | */ 8 | struct ListNode { 9 | int val; 10 | ListNode *next; 11 | ListNode(int x) : val(x), next(NULL) {} 12 | }; 13 | #endif // !_LISTNODE_H_ 14 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:LeetCodeCpp 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 LeetCodeCpp 应用程序。 6 | 7 | 本文件概要介绍组成 LeetCodeCpp 应用程序的每个文件的内容。 8 | 9 | 10 | LeetCodeCpp.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | LeetCodeCpp.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | LeetCodeCpp.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 LeetCodeCpp.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/TreeNode.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef _TREENODE_H_ 3 | #define _TREENODE_H_ 4 | 5 | /** 6 | * Definition for a binary tree node. 7 | */ 8 | struct TreeNode { 9 | int val; 10 | TreeNode *left; 11 | TreeNode *right; 12 | TreeNode(int x) : val(x), left(NULL), right(NULL) {} 13 | }; 14 | 15 | #endif // !_TREENODE_H_ 16 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/resource.h -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/stdafx.cpp -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/stdafx.h -------------------------------------------------------------------------------- /LeetCode/LeetCodeCpp/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeCpp/targetver.h -------------------------------------------------------------------------------- /LeetCode/LeetCodePython/349.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | class Solution: 5 | def intersection(self, nums1, nums2): 6 | """ 7 | :type nums1: List[int] 8 | :type nums2: List[int] 9 | :rtype: List[int] 10 | """ 11 | tmp = set(nums1).intersection(nums2) 12 | return list(tmp) 13 | 14 | 15 | if __name__ == '__main__': 16 | s = Solution() 17 | ret = s.intersection([1, 2, 2, 1], [2, 2]) 18 | print(ret) 19 | -------------------------------------------------------------------------------- /LeetCode/LeetCodePython/566.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | class Solution: 5 | def matrixReshape(self, nums, r, c): 6 | """ 7 | :type nums: List[List[int]] 8 | :type r: int 9 | :type c: int 10 | :rtype: List[List[int]] 11 | """ 12 | origin_r = len(nums) # 行 13 | origin_c = len(nums[0]) # 列 14 | if origin_c * origin_r == r * c: # 可以reshape 15 | temp = [num for row in nums for num in row] # 展开成一维数组 16 | new_matrix = [[0 for j in range(c)] for i in range(r)] 17 | for i in range(r): 18 | for j in range(c): 19 | new_matrix[i][j] = temp[i * c + j] 20 | return new_matrix 21 | else: # 无法reshape 22 | return nums 23 | 24 | 25 | -------------------------------------------------------------------------------- /LeetCode/LeetCodePython/LeetCodePython.pyproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | 2.0 6 | c0dff160-18ca-4548-b288-4503ddf26577 7 | 8 | 9 | 349.py 10 | 11 | 12 | . 13 | . 14 | LeetCodePython 15 | PythonApplication1 16 | 17 | 18 | true 19 | false 20 | 21 | 22 | true 23 | false 24 | 25 | 26 | 10.0 27 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /LeetCode/LeetCodeSql/175组合两个表.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeSql/175组合两个表.sql -------------------------------------------------------------------------------- /LeetCode/LeetCodeSql/182.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeSql/182.sql -------------------------------------------------------------------------------- /LeetCode/LeetCodeSql/595.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeSql/595.sql -------------------------------------------------------------------------------- /LeetCode/LeetCodeSql/620有趣的电影.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LeetCode/LeetCodeSql/620有趣的电影.sql -------------------------------------------------------------------------------- /LeetCode/LeetCodeSql/LeetCodeSql.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 源文件 23 | 24 | 25 | 源文件 26 | 27 | 28 | 源文件 29 | 30 | 31 | -------------------------------------------------------------------------------- /LinkList/LinkList.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 32 | 33 | 源文件 34 | 35 | 36 | 源文件 37 | 38 | 39 | 源文件 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | -------------------------------------------------------------------------------- /LinkList/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:LinkList 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 LinkList 应用程序。 6 | 7 | 本文件概要介绍组成 LinkList 应用程序的每个文件的内容。 8 | 9 | 10 | LinkList.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | LinkList.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | LinkList.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 LinkList.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /LinkList/josephu_problem.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LinkList/josephu_problem.cpp -------------------------------------------------------------------------------- /LinkList/link_list.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LinkList/link_list.cpp -------------------------------------------------------------------------------- /LinkList/link_list.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LinkList/link_list.h -------------------------------------------------------------------------------- /LinkList/link_list_main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LinkList/link_list_main.cpp -------------------------------------------------------------------------------- /LinkList/single_curcular_linked_list.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LinkList/single_curcular_linked_list.cpp -------------------------------------------------------------------------------- /LinkList/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LinkList/stdafx.cpp -------------------------------------------------------------------------------- /LinkList/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LinkList/stdafx.h -------------------------------------------------------------------------------- /LinkList/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/LinkList/targetver.h -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Introducation 2 | 主要是方便自己学习和复习,整合了一下基础知识和刷题内容。主要是用cpp,部分用C#,LeetCode有少量Python和SQL(mqsql)的 3 | 4 | 我看到有clone的,如果觉得有用,请star一下,给予支持,谢谢 5 | 6 | # Content 7 | 主要包括: 8 | 9 | 基础知识部分 10 | * 1、基础算法 11 | * 2、数据结构 12 | * 3、设计模式(C#版) 13 | * 4、多线程 14 | * 5、STL 15 | 16 | 原tcp/ip部分迁移到新仓库https://github.com/landbroken/TCP-IP 17 | 18 | 刷题部分 19 | * 1、LeetCode刷题 20 | * 2、华为OJ 21 | 22 | 单元测试部分 23 | * 1、以上各内容的单元测试 24 | 25 | # Related repositories 26 | JavaLearning:https://github.com/landbroken/JavaLearning 27 | 28 | # Contributor 29 | LinYulong 30 | 31 | 欢迎交流 32 | 邮箱 im.linyulong@qq.com 33 | 我的CSDN博客 https://blog.csdn.net/u012692537 34 | -------------------------------------------------------------------------------- /STL/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:STL 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 STL 应用程序。 6 | 7 | 本文件概要介绍组成 STL 应用程序的每个文件的内容。 8 | 9 | 10 | STL.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | STL.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | STL.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 STL.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /STL/STL.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 32 | 33 | 源文件 34 | 35 | 36 | 源文件 37 | 38 | 39 | 源文件 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | 源文件 49 | 50 | 51 | 源文件 52 | 53 | 54 | -------------------------------------------------------------------------------- /STL/list.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/STL/list.cpp -------------------------------------------------------------------------------- /STL/map.cpp: -------------------------------------------------------------------------------- 1 | #include"stdafx.h" 2 | #include 3 | #include 4 | #include 5 | #include"stl_demo.h" 6 | using namespace std; 7 | 8 | MapDemo::MapDemo() 9 | { 10 | } 11 | 12 | MapDemo::~MapDemo() 13 | { 14 | } 15 | 16 | void MapDemo::Insert(int key,string value) 17 | { 18 | mapStudent.insert(pair(key, value)); 19 | } 20 | 21 | void MapDemo::Output() 22 | { 23 | for (iter = mapStudent.begin(); iter != mapStudent.end(); iter++) 24 | { 25 | cout << iter->first; 26 | cout << " "; 27 | cout << iter->second; 28 | cout << endl; 29 | } 30 | } 31 | 32 | void MapDemo::Find(const int& key) 33 | { 34 | auto ret = mapStudent.find(key); 35 | if (ret!=mapStudent.end()) 36 | { 37 | cout << "key=" << ret->first << "value=" << ret->second << endl; 38 | } 39 | else 40 | { 41 | cout << "can't find this key" << endl; 42 | } 43 | } 44 | 45 | std::map MapDemo::GetMap() 46 | { 47 | return mapStudent; 48 | } -------------------------------------------------------------------------------- /STL/set.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/STL/set.cpp -------------------------------------------------------------------------------- /STL/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/STL/stdafx.cpp -------------------------------------------------------------------------------- /STL/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/STL/stdafx.h -------------------------------------------------------------------------------- /STL/stl_demo.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/STL/stl_demo.h -------------------------------------------------------------------------------- /STL/stl_main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/STL/stl_main.cpp -------------------------------------------------------------------------------- /STL/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/STL/targetver.h -------------------------------------------------------------------------------- /STL/vector.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/STL/vector.cpp -------------------------------------------------------------------------------- /STL/常用算法.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/STL/常用算法.cpp -------------------------------------------------------------------------------- /Search/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:Search 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 Search 应用程序。 6 | 7 | 本文件概要介绍组成 Search 应用程序的每个文件的内容。 8 | 9 | 10 | Search.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | Search.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | Search.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 Search.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /Search/Search.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 32 | 33 | 源文件 34 | 35 | 36 | 源文件 37 | 38 | 39 | 源文件 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | 源文件 49 | 50 | 51 | 源文件 52 | 53 | 54 | 源文件 55 | 56 | 57 | 源文件 58 | 59 | 60 | 61 | 62 | 源文件 63 | 64 | 65 | -------------------------------------------------------------------------------- /Search/binary_search.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Search/binary_search.cpp -------------------------------------------------------------------------------- /Search/block_search.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Search/block_search.cpp -------------------------------------------------------------------------------- /Search/fibonacci_search.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Search/fibonacci_search.cpp -------------------------------------------------------------------------------- /Search/hash_search.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Search/hash_search.cpp -------------------------------------------------------------------------------- /Search/insertion_search.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Search/insertion_search.cpp -------------------------------------------------------------------------------- /Search/search.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Search/search.h -------------------------------------------------------------------------------- /Search/search_main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Search/search_main.cpp -------------------------------------------------------------------------------- /Search/sequence_search.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Search/sequence_search.cpp -------------------------------------------------------------------------------- /Search/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Search/stdafx.cpp -------------------------------------------------------------------------------- /Search/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Search/stdafx.h -------------------------------------------------------------------------------- /Search/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Search/targetver.h -------------------------------------------------------------------------------- /Search/tree_search.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Search/tree_search.cpp -------------------------------------------------------------------------------- /Search/性能对比.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Search/性能对比.jpg -------------------------------------------------------------------------------- /Stack/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:Stack 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 Stack 应用程序。 6 | 7 | 本文件概要介绍组成 Stack 应用程序的每个文件的内容。 8 | 9 | 10 | Stack.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | Stack.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | Stack.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 Stack.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /Stack/Stack.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 32 | 33 | 源文件 34 | 35 | 36 | 源文件 37 | 38 | 39 | 源文件 40 | 41 | 42 | -------------------------------------------------------------------------------- /Stack/StackDemo.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Stack/StackDemo.h -------------------------------------------------------------------------------- /Stack/array_stack.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | #include"StackDemo.h" 4 | using namespace std; 5 | 6 | ArrStack::ArrStack(int maxSize) 7 | { 8 | size = maxSize; 9 | tos = -1; 10 | contain = new int[size]; 11 | } 12 | 13 | ArrStack::~ArrStack() 14 | { 15 | if (contain!=nullptr) 16 | { 17 | delete contain; 18 | contain = nullptr; 19 | } 20 | } 21 | 22 | void ArrStack::Push(const int & element) 23 | { 24 | if (!IsFull()) 25 | { 26 | ++tos; 27 | contain[tos] = element; 28 | } 29 | } 30 | 31 | int ArrStack::GetTop() const 32 | { 33 | if (!IsEmpty()) 34 | { 35 | return contain[tos]; 36 | } 37 | else 38 | { 39 | throw std::exception("NULL"); 40 | } 41 | } 42 | 43 | void ArrStack::Pop() 44 | { 45 | if (!IsEmpty()) 46 | { 47 | tos--; 48 | } 49 | } 50 | 51 | bool ArrStack::IsEmpty() const 52 | { 53 | return tos == -1; 54 | } 55 | 56 | bool ArrStack::IsFull() const 57 | { 58 | return tos >= size - 1; 59 | } 60 | 61 | void ArrStack::MakeEmpty() 62 | { 63 | tos = -1; 64 | } 65 | -------------------------------------------------------------------------------- /Stack/stack_main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Stack/stack_main.cpp -------------------------------------------------------------------------------- /Stack/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Stack/stdafx.cpp -------------------------------------------------------------------------------- /Stack/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Stack/stdafx.h -------------------------------------------------------------------------------- /Stack/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Stack/targetver.h -------------------------------------------------------------------------------- /Test/LeetCodeCppTest/LeetCodeCppTest.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 26 | 27 | 源文件 28 | 29 | 30 | 源文件 31 | 32 | 33 | -------------------------------------------------------------------------------- /Test/LeetCodeCppTest/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Test/LeetCodeCppTest/stdafx.cpp -------------------------------------------------------------------------------- /Test/LeetCodeCppTest/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Test/LeetCodeCppTest/stdafx.h -------------------------------------------------------------------------------- /Test/LeetCodeCppTest/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Test/LeetCodeCppTest/targetver.h -------------------------------------------------------------------------------- /Test/LeetCodeCppTest/unittest1.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Test/LeetCodeCppTest/unittest1.cpp -------------------------------------------------------------------------------- /Test/STLTest/STLTest.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 26 | 27 | 源文件 28 | 29 | 30 | 源文件 31 | 32 | 33 | -------------------------------------------------------------------------------- /Test/STLTest/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Test/STLTest/stdafx.cpp -------------------------------------------------------------------------------- /Test/STLTest/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Test/STLTest/stdafx.h -------------------------------------------------------------------------------- /Test/STLTest/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Test/STLTest/targetver.h -------------------------------------------------------------------------------- /Test/STLTest/unittest_stl.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Test/STLTest/unittest_stl.cpp -------------------------------------------------------------------------------- /Test/SearchTest/SearchTest.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 26 | 27 | 源文件 28 | 29 | 30 | 源文件 31 | 32 | 33 | -------------------------------------------------------------------------------- /Test/SearchTest/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Test/SearchTest/stdafx.cpp -------------------------------------------------------------------------------- /Test/SearchTest/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Test/SearchTest/stdafx.h -------------------------------------------------------------------------------- /Test/SearchTest/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Test/SearchTest/targetver.h -------------------------------------------------------------------------------- /Test/SearchTest/unittest_search.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "CppUnitTest.h" 3 | #include "../../Search/search.h" 4 | using namespace Microsoft::VisualStudio::CppUnitTestFramework; 5 | 6 | namespace SearchTest 7 | { 8 | TEST_CLASS(UnitTestSearch) 9 | { 10 | private: 11 | const int static arrSize = 10; 12 | int a[arrSize] = { 1,2,3,4,5,10,11,12,13,14 }; 13 | public: 14 | 15 | TEST_METHOD(TestSequenceSearch) 16 | { 17 | int ret = 0; 18 | ret = SequenceSearch(a, 10, arrSize); 19 | Assert::AreEqual(5, ret); 20 | ret = SequenceSearch(a, 6, arrSize); 21 | Assert::AreEqual(-1, ret); 22 | } 23 | 24 | TEST_METHOD(TestBinarySearch) 25 | { 26 | int ret = 0; 27 | ret = BinarySearch(a, 10, arrSize); 28 | Assert::AreEqual(5, ret); 29 | ret = BinarySearch_Recursion(a, 11, 0, arrSize - 1); 30 | Assert::AreEqual(6, ret); 31 | ret = BinarySearch(a, 6, arrSize); 32 | Assert::AreEqual(-1, ret); 33 | ret = BinarySearch_Recursion(a, 6, 0, arrSize - 1); 34 | Assert::AreEqual(-1, ret); 35 | } 36 | 37 | TEST_METHOD(TestInsertionSearch) 38 | { 39 | int ret = 0; 40 | ret = InsertionSearch(a, 10, 0, arrSize - 1); 41 | Assert::AreEqual(5, ret); 42 | ret = InsertionSearch_Recursion(a, 11, 0, arrSize - 1); 43 | Assert::AreEqual(6, ret); 44 | ret = InsertionSearch(a, 6, 0, arrSize - 1); 45 | Assert::AreEqual(-1, ret); 46 | ret = InsertionSearch_Recursion(a, 6, 0, arrSize - 1); 47 | Assert::AreEqual(-1, ret); 48 | } 49 | }; 50 | } -------------------------------------------------------------------------------- /Test/SortTest/UnitTest1.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 26 | 27 | 源文件 28 | 29 | 30 | 源文件 31 | 32 | 33 | -------------------------------------------------------------------------------- /Test/SortTest/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Test/SortTest/stdafx.cpp -------------------------------------------------------------------------------- /Test/SortTest/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Test/SortTest/stdafx.h -------------------------------------------------------------------------------- /Test/SortTest/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Test/SortTest/targetver.h -------------------------------------------------------------------------------- /Test/SortTest/unittest_sort.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/Test/SortTest/unittest_sort.cpp -------------------------------------------------------------------------------- /ThreadCSharp/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /ThreadCSharp/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace ThreadCSharp 2 | { 3 | partial class Form1 4 | { 5 | /// 6 | /// 必需的设计器变量。 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// 清理所有正在使用的资源。 12 | /// 13 | /// 如果应释放托管资源,为 true;否则为 false。 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows 窗体设计器生成的代码 24 | 25 | /// 26 | /// 设计器支持所需的方法 - 不要修改 27 | /// 使用代码编辑器修改此方法的内容。 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.button1 = new System.Windows.Forms.Button(); 32 | this.textBox1 = new System.Windows.Forms.TextBox(); 33 | this.SuspendLayout(); 34 | // 35 | // button1 36 | // 37 | this.button1.Location = new System.Drawing.Point(12, 12); 38 | this.button1.Name = "button1"; 39 | this.button1.Size = new System.Drawing.Size(75, 23); 40 | this.button1.TabIndex = 0; 41 | this.button1.Text = "button1"; 42 | this.button1.UseVisualStyleBackColor = true; 43 | this.button1.Click += new System.EventHandler(this.button1_Click); 44 | // 45 | // textBox1 46 | // 47 | this.textBox1.Location = new System.Drawing.Point(127, 10); 48 | this.textBox1.Multiline = true; 49 | this.textBox1.Name = "textBox1"; 50 | this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; 51 | this.textBox1.Size = new System.Drawing.Size(859, 450); 52 | this.textBox1.TabIndex = 1; 53 | // 54 | // Form1 55 | // 56 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); 57 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 58 | this.ClientSize = new System.Drawing.Size(998, 472); 59 | this.Controls.Add(this.textBox1); 60 | this.Controls.Add(this.button1); 61 | this.Name = "Form1"; 62 | this.Text = "Form1"; 63 | this.Load += new System.EventHandler(this.Form1_Load); 64 | this.ResumeLayout(false); 65 | this.PerformLayout(); 66 | 67 | } 68 | 69 | #endregion 70 | 71 | private System.Windows.Forms.Button button1; 72 | private System.Windows.Forms.TextBox textBox1; 73 | } 74 | } 75 | 76 | -------------------------------------------------------------------------------- /ThreadCSharp/Form1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading; 9 | using System.Threading.Tasks; 10 | using System.Windows.Forms; 11 | 12 | namespace ThreadCSharp 13 | { 14 | public partial class Form1 : Form 15 | { 16 | const int cycleNum = 15; 17 | static AutoResetEvent myEvent = new AutoResetEvent(false); 18 | 19 | public Form1() 20 | { 21 | InitializeComponent(); 22 | } 23 | 24 | private void Form1_Load(object sender, EventArgs e) 25 | { 26 | 27 | } 28 | 29 | public void testFun(object obj) 30 | { 31 | string output = $"{"Begin:" + DateTime.Now.ToString()}:第{obj.ToString()}个线程"; 32 | SetMessage(textBox1, output); 33 | Thread.Sleep(3000); 34 | string end = $"{"End:" + DateTime.Now.ToString()}:第{obj.ToString()}个线程"; 35 | SetMessage(textBox1, end); 36 | if (obj.ToString() == "10") 37 | { 38 | myEvent.Set(); 39 | } 40 | } 41 | 42 | private void button1_Click(object sender, EventArgs e) 43 | { 44 | SetMessage(textBox1, $"主线程执行!{DateTime.Now.ToString()}"); 45 | ThreadPool.SetMinThreads(1, 1); 46 | ThreadPool.SetMaxThreads(5, 5); 47 | for (int i = 1; i <= cycleNum; i++) 48 | { 49 | ThreadPool.QueueUserWorkItem(new WaitCallback(testFun), i.ToString()); 50 | } 51 | SetMessage(textBox1, $"主线程结束!{DateTime.Now.ToString()}"); 52 | myEvent.WaitOne(); 53 | SetMessage(textBox1, $"线程池终止!{DateTime.Now.ToString()}"); 54 | } 55 | 56 | delegate void SetMessageCallBack(TextBox txtIn, string MyMessage); 57 | private void SetMessage(TextBox txtIn, string MyMessageIn) 58 | { 59 | try 60 | { 61 | if (!MyMessageIn.EndsWith(Environment.NewLine)) 62 | { 63 | MyMessageIn += Environment.NewLine;//加上换行符 64 | } 65 | if (this.InvokeRequired) 66 | { 67 | SetMessageCallBack tmpMessage = new SetMessageCallBack(SetMessage); 68 | this.BeginInvoke(tmpMessage, new object[] { txtIn, MyMessageIn }); 69 | } 70 | else 71 | { 72 | txtIn.Text += MyMessageIn; 73 | } 74 | } 75 | catch (Exception ex) 76 | { 77 | //线程时间太短,容易在关闭窗口时引起异常: 78 | //无法访问已释放的对象。对象名:“Form1”。 79 | string tmp = ex.Message; 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /ThreadCSharp/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace ThreadCSharp 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// 应用程序的主入口点。 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new Form1()); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ThreadCSharp/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("ThreadCSharp")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("ThreadCSharp")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | //将 ComVisible 设置为 false 将使此程序集中的类型 18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("c7ad6b38-79be-4faa-9344-2f4d7a0bd407")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /ThreadCSharp/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本: 4.0.30319.42000 5 | // 6 | // 对此文件的更改可能导致不正确的行为,如果 7 | // 重新生成代码,则所做更改将丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ThreadCSharp.Properties 12 | { 13 | 14 | 15 | /// 16 | /// 强类型资源类,用于查找本地化字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或删除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// 返回此类使用的缓存 ResourceManager 实例。 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ThreadCSharp.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// 覆盖当前线程的 CurrentUICulture 属性 56 | /// 使用此强类型的资源类的资源查找。 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /ThreadCSharp/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace ThreadCSharp.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ThreadCSharp/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ThreadCpp/1_thread.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/ThreadCpp/1_thread.cpp -------------------------------------------------------------------------------- /ThreadCpp/2_move.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/ThreadCpp/2_move.cpp -------------------------------------------------------------------------------- /ThreadCpp/3_mutex.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/ThreadCpp/3_mutex.cpp -------------------------------------------------------------------------------- /ThreadCpp/4_timed_mutex.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/ThreadCpp/4_timed_mutex.cpp -------------------------------------------------------------------------------- /ThreadCpp/5_thread_local_storage.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/ThreadCpp/5_thread_local_storage.cpp -------------------------------------------------------------------------------- /ThreadCpp/6_condition_variable.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/ThreadCpp/6_condition_variable.cpp -------------------------------------------------------------------------------- /ThreadCpp/7_atomic.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | struct AtomicCounter { 4 | std::atomic value; 5 | 6 | void increment() 7 | { 8 | ++value; 9 | } 10 | 11 | void decrement() 12 | { 13 | --value; 14 | } 15 | 16 | int get() 17 | { 18 | return value; 19 | } 20 | }; -------------------------------------------------------------------------------- /ThreadCpp/8_call_once.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | using namespace std; 3 | 4 | std::once_flag flag; 5 | 6 | void do_once() 7 | { 8 | std::call_once(flag, []() {std::cout << "called" << std::endl;}); 9 | } 10 | 11 | int call_once_demo() 12 | { 13 | std::thread t1(do_once); 14 | std::thread t2(do_once); 15 | std::thread t3(do_once); 16 | 17 | t1.join(); 18 | t2.join(); 19 | t3.join(); 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /ThreadCpp/ReadMe.md: -------------------------------------------------------------------------------- 1 | # 头文件 2 | C++11 新标准中引入了四个头文件来支持多线程编程,他们分别是 3 | 4 | - \:该头文主要声明了两个类, std::atomic 和 std\::atomic_flag,另外还声明了一套 C 风格的原子类型和与 C 兼容的原子操作的函数。 5 | - \:该头文件主要声明了 std::thread 类,另外 std\::this_thread 命名空间也在该头文件中。 6 | - \:该头文件主要声明了与互斥量(mutex)相关的类,包括 std::mutex 系列类,std\::lock_guard, std\::unique_lock, 以及其他的类型和函数。 7 | - \:该头文件主要声明了与条件变量相关的类,包括 std\::condition_variable 和 std\::condition_variable_any。 8 | - \:该头文件主要声明了 std\::promise, std\::package_task 两个 Provider 类,以及 std\::future 和 std\::shared_future 两个 Future 类,另外还有一些与之相关的类型和函数,std::async() 函数就声明在此头文件中。 9 | 10 | # 参考文献 11 | 12 | 1. [C++11多线程(简约但不简单)](https://www.jianshu.com/p/dcce068ee32b) -------------------------------------------------------------------------------- /ThreadCpp/ThreadCpp.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/ThreadCpp/ThreadCpp.cpp -------------------------------------------------------------------------------- /ThreadCpp/ThreadCpp.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 29 | 30 | 源文件 31 | 32 | 33 | 源文件 34 | 35 | 36 | 源文件 37 | 38 | 39 | 源文件 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | 源文件 49 | 50 | 51 | 源文件 52 | 53 | 54 | 源文件 55 | 56 | 57 | 源文件 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /ThreadCpp/ThreadLearning.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/ThreadCpp/ThreadLearning.h -------------------------------------------------------------------------------- /ThreadCpp/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/ThreadCpp/stdafx.cpp -------------------------------------------------------------------------------- /ThreadCpp/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/ThreadCpp/stdafx.h -------------------------------------------------------------------------------- /ThreadCpp/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/ThreadCpp/targetver.h -------------------------------------------------------------------------------- /TreeCpp/BiTree.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/TreeCpp/BiTree.h -------------------------------------------------------------------------------- /TreeCpp/Huffman.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/TreeCpp/Huffman.h -------------------------------------------------------------------------------- /TreeCpp/HuffmanNode.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/TreeCpp/HuffmanNode.h -------------------------------------------------------------------------------- /TreeCpp/MinHeap.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/TreeCpp/MinHeap.h -------------------------------------------------------------------------------- /TreeCpp/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:TreeCpp 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 TreeCpp 应用程序。 6 | 7 | 本文件概要介绍组成 TreeCpp 应用程序的每个文件的内容。 8 | 9 | 10 | TreeCpp.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | TreeCpp.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | TreeCpp.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 TreeCpp.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /TreeCpp/TreeCpp.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 头文件 32 | 33 | 34 | 头文件 35 | 36 | 37 | 头文件 38 | 39 | 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | -------------------------------------------------------------------------------- /TreeCpp/TreeCpp_main.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/TreeCpp/TreeCpp_main.cpp -------------------------------------------------------------------------------- /TreeCpp/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/TreeCpp/stdafx.cpp -------------------------------------------------------------------------------- /TreeCpp/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/TreeCpp/stdafx.h -------------------------------------------------------------------------------- /TreeCpp/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/TreeCpp/targetver.h -------------------------------------------------------------------------------- /string/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:string 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 string 应用程序。 6 | 7 | 本文件概要介绍组成 string 应用程序的每个文件的内容。 8 | 9 | 10 | string.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | string.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | string.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 string.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /string/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/string/stdafx.cpp -------------------------------------------------------------------------------- /string/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/string/stdafx.h -------------------------------------------------------------------------------- /string/string.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/string/string.cpp -------------------------------------------------------------------------------- /string/string.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 29 | 30 | 源文件 31 | 32 | 33 | 源文件 34 | 35 | 36 | -------------------------------------------------------------------------------- /string/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/string/targetver.h -------------------------------------------------------------------------------- /templateDemo/BiTree.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "BiTree.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | -------------------------------------------------------------------------------- /templateDemo/BiTree.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/templateDemo/BiTree.h -------------------------------------------------------------------------------- /templateDemo/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:templateDemo 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 templateDemo 应用程序。 6 | 7 | 本文件概要介绍组成 templateDemo 应用程序的每个文件的内容。 8 | 9 | 10 | templateDemo.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | templateDemo.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | templateDemo.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 templateDemo.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /templateDemo/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/templateDemo/stdafx.cpp -------------------------------------------------------------------------------- /templateDemo/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/templateDemo/stdafx.h -------------------------------------------------------------------------------- /templateDemo/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/templateDemo/targetver.h -------------------------------------------------------------------------------- /templateDemo/templateDemo.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/templateDemo/templateDemo.cpp -------------------------------------------------------------------------------- /templateDemo/templateDemo.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 32 | 33 | 源文件 34 | 35 | 36 | 源文件 37 | 38 | 39 | 源文件 40 | 41 | 42 | -------------------------------------------------------------------------------- /基础/位运算/BitOperation.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/基础/位运算/BitOperation.cpp -------------------------------------------------------------------------------- /基础/位运算/BitOperation.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/基础/位运算/BitOperation.h -------------------------------------------------------------------------------- /基础/位运算/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:位运算 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 位运算 应用程序。 6 | 7 | 本文件概要介绍组成 位运算 应用程序的每个文件的内容。 8 | 9 | 10 | 位运算.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | 位运算.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | 位运算.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 位运算.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /基础/位运算/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/基础/位运算/stdafx.cpp -------------------------------------------------------------------------------- /基础/位运算/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/基础/位运算/stdafx.h -------------------------------------------------------------------------------- /基础/位运算/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/基础/位运算/targetver.h -------------------------------------------------------------------------------- /基础/位运算/位运算.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/基础/位运算/位运算.cpp -------------------------------------------------------------------------------- /基础/位运算/位运算.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 32 | 33 | 源文件 34 | 35 | 36 | 源文件 37 | 38 | 39 | 源文件 40 | 41 | 42 | -------------------------------------------------------------------------------- /基础/内存管理/memory/ReadMe.md: -------------------------------------------------------------------------------- 1 | # 一、内存分配 2 | 3 | ## malloc与new的区别 4 | 5 | id|malloc|new 6 | -|-|- 7 | 1 | malloc是函数,要#include头文件 | new是c++的关键字,不要#include 8 | 2 | malloc返回的是void*,需要强制转换为所需类型 | new返回的是所需类型 9 | 3 | malloc用free释放 | new用delete释放 10 | 11 | # 二、内存操作 12 | ## memset 13 | 在头文件中定义 14 | - void * memset(void * _Dst,int _Val,size_t _Size); 15 | - errno_t memset_s(void * dest,rsize_t destsz,int ch,rsize_t count) 16 | 17 | 用途:将某一段内存设置为指定值 18 | -------------------------------------------------------------------------------- /基础/内存管理/memory/memory.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/基础/内存管理/memory/memory.cpp -------------------------------------------------------------------------------- /基础/内存管理/memory/memory.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 26 | 27 | 源文件 28 | 29 | 30 | 源文件 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /基础/内存管理/memory/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/基础/内存管理/memory/stdafx.cpp -------------------------------------------------------------------------------- /基础/内存管理/memory/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/基础/内存管理/memory/stdafx.h -------------------------------------------------------------------------------- /基础/内存管理/memory/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/基础/内存管理/memory/targetver.h -------------------------------------------------------------------------------- /基础/指针/pointer/ReadMe.md: -------------------------------------------------------------------------------- 1 | # 简介 2 | 我们知道除了静态内存和栈内存外,每个程序还有一个内存池,这部分内存被称为自由空间或者堆。程序用堆来存储动态分配的对象即那些在程序运行时分配的对象,当动态对象不再使用时,我们的代码必须显式的销毁它们。 3 | 4 | 在C++中,动态内存的管理是用一对运算符完成的:new和delete,new:在动态内存中为对象分配一块空间并返回一个指向该对象的指针,delete:指向一个动态独享的指针,销毁对象,并释放与之关联的内存。 5 | 6 | 动态内存管理经常会出现两种问题:一种是忘记释放内存,会造成内存泄漏;一种是尚有指针引用内存的情况下就释放了它,就会产生引用非法内存的指针。 7 | 8 | 为了更加容易(更加安全)的使用动态内存,引入了智能指针的概念。智能指针的行为类似常规指针,重要的区别是它负责自动释放所指向的对象。 9 | 1. auto_ptr。是 C++98 提供的解决方案,C+11 已将其摒弃。用unique_ptr替代。 10 | 2. unique_ptr。“独占”所指向的对象 11 | 3. shared_ptr。允许多个指针指向同一个对象 12 | 4. weak_ptr。它是一种弱引用,指向shared_ptr所管理的对象 13 | 14 | 定义在memory头文件中。 15 | 16 | # 参考文献 17 | 1. [STL 四种智能指针](https://blog.csdn.net/k346k346/article/details/81478223) 18 | 2. [C++智能指针详解](https://blog.csdn.net/flowing_wind/article/details/81301001) 19 | 3. [智能指针 unique_ptr 详解](https://blog.csdn.net/afei__/article/details/80670283) -------------------------------------------------------------------------------- /基础/指针/pointer/pointer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/基础/指针/pointer/pointer.cpp -------------------------------------------------------------------------------- /基础/指针/pointer/pointer.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 29 | 30 | 源文件 31 | 32 | 33 | 源文件 34 | 35 | 36 | 源文件 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /基础/指针/pointer/ptr.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef _PTR_H_ 3 | #define _PTR_H_ 4 | 5 | #define E_OK 0; 6 | 7 | int unique_demo(); 8 | 9 | #endif _PTR_H_ -------------------------------------------------------------------------------- /基础/指针/pointer/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/基础/指针/pointer/stdafx.cpp -------------------------------------------------------------------------------- /基础/指针/pointer/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/基础/指针/pointer/stdafx.h -------------------------------------------------------------------------------- /基础/指针/pointer/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/基础/指针/pointer/targetver.h -------------------------------------------------------------------------------- /基础/指针/pointer/unique_ptr_demo.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/基础/指针/pointer/unique_ptr_demo.cpp -------------------------------------------------------------------------------- /排序/ReadMe.txt: -------------------------------------------------------------------------------- 1 | ======================================================================== 2 | 控制台应用程序:排序 项目概述 3 | ======================================================================== 4 | 5 | 应用程序向导已为您创建了此 排序 应用程序。 6 | 7 | 本文件概要介绍组成 排序 应用程序的每个文件的内容。 8 | 9 | 10 | 排序.vcxproj 11 | 这是使用应用程序向导生成的 VC++ 项目的主项目文件,其中包含生成该文件的 Visual C++ 的版本信息,以及有关使用应用程序向导选择的平台、配置和项目功能的信息。 12 | 13 | 排序.vcxproj.filters 14 | 这是使用“应用程序向导”生成的 VC++ 项目筛选器文件。它包含有关项目文件与筛选器之间的关联信息。在 IDE 中,通过这种关联,在特定节点下以分组形式显示具有相似扩展名的文件。例如,“.cpp”文件与“源文件”筛选器关联。 15 | 16 | 排序.cpp 17 | 这是主应用程序源文件。 18 | 19 | ///////////////////////////////////////////////////////////////////////////// 20 | 其他标准文件: 21 | 22 | StdAfx.h, StdAfx.cpp 23 | 这些文件用于生成名为 排序.pch 的预编译头 (PCH) 文件和名为 StdAfx.obj 的预编译类型文件。 24 | 25 | ///////////////////////////////////////////////////////////////////////////// 26 | 其他注释: 27 | 28 | 应用程序向导使用“TODO:”注释来指示应添加或自定义的源代码部分。 29 | 30 | ///////////////////////////////////////////////////////////////////////////// 31 | -------------------------------------------------------------------------------- /排序/insertion_sort.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/排序/insertion_sort.cpp -------------------------------------------------------------------------------- /排序/merge_sort.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "sort.h" 3 | #include 4 | using namespace std; 5 | 6 | /* 7 | @brief 合并操作 8 | 将两个有序表合并成一个有序表 9 | */ 10 | void Merge(int* a, int left, int mid, int right) 11 | { 12 | int len = right - left + 1; // 数组的长度 13 | int *temp= new int[len]; // 分配个临时数组 14 | //int temp[100]; // 分配个临时数组 15 | int k = 0; 16 | int i = left; // 前一数组的起始元素 17 | int j = mid + 1; // 后一数组的起始元素 18 | while (i <= mid && j <= right) 19 | { 20 | //选择较小的存入临时数组 21 | if (a[i]data[j+1]) 14 | { 15 | swap(&data[j], &data[j+1]); 16 | } 17 | } 18 | } 19 | } 20 | 21 | /* 22 | @brief 鸡尾酒排序,也叫定向冒泡排序 23 | // 分类 -------------- 内部比较排序 24 | // 数据结构 ---------- 数组 25 | // 最差时间复杂度 ---- O(n^2) 26 | // 最优时间复杂度 ---- 如果序列在一开始已经大部分排序过的话,会接近O(n) 27 | // 平均时间复杂度 ---- O(n^2) 28 | // 所需辅助空间 ------ O(1) 29 | // 稳定性 ------------ 稳定 30 | 31 | 此算法与冒泡排序的不同处在于从低到高然后从高到低, 32 | 而冒泡排序则仅从低到高去比较序列里的每个元素。他 33 | 可以得到比冒泡排序稍微好一点的效能。 34 | 35 | 在乱数序列的状态下,鸡尾酒排序与冒泡排序的效率都很差劲。 36 | */ 37 | void CocktailSort(int* A, int length) 38 | { 39 | int left = 0; // 初始化边界 40 | int right = length - 1; 41 | while (left < right) 42 | { 43 | for (int i = left; i < right; i++) // 前半轮,将最大元素放到后面 44 | { 45 | if (A[i] > A[i + 1]) 46 | { 47 | swap(&A[i], &A[i + 1]); 48 | } 49 | } 50 | right--; 51 | for (int i = right; i > left; i--) // 后半轮,将最小元素放到前面 52 | { 53 | if (A[i - 1] > A[i]) 54 | { 55 | swap(&A[i - 1], &A[i]); 56 | } 57 | } 58 | left++; 59 | } 60 | } 61 | 62 | 63 | /* 64 | @brief 快速排序的排序部分 65 | */ 66 | int Partition(int* A, int left, int right) // 划分函数 67 | { 68 | int pivot = A[right]; // 这里每次都选择最后一个元素作为基准 69 | int tail = left - 1; // tail为小于基准的子数组最后一个元素的索引 70 | for (int i = left; i < right; i++) // 遍历基准以外的其他元素 71 | { 72 | if (A[i] <= pivot) // 把小于等于基准的元素放到前一个子数组末尾 73 | { 74 | tail++; 75 | swap(&A[tail], &A[i]); 76 | } 77 | } 78 | swap(&A[tail + 1], &A[right]); // 最后把基准放到前一个子数组的后边,剩下的子数组既是大于基准的子数组 79 | // 该操作很有可能把后面元素的稳定性打乱,所以快速排序是不稳定的排序算法 80 | 81 | return tail + 1; // 返回基准的索引 82 | } 83 | 84 | /* 85 | @brief 快速排序 86 | @基本思想 87 | 通过一趟排序将待排记录分隔成独立的两部分,其中一部分记录的关键字 88 | 均比另一部分的关键字小,则可分别对这两部分记录继续进行排序,以达 89 | 到整个序列有序。 90 | 91 | @算法描述 92 | •从数列中挑出一个元素,称为 “基准”(pivot); 93 | •重新排序数列,所有元素比基准值小的摆放在基准前面,所有元素比基准 94 | 值大的摆在基准的后面(相同的数可以到任一边)。在这个分区退出之后, 95 | 该基准就处于数列的中间位置。这个称为分区(partition)操作; 96 | •递归地(recursive)把小于基准值元素的子数列和大于基准值元素的子数 97 | 列排序。 98 | 99 | 100 | @分析 101 | 在平均状况下,排序n个元素要O(nlogn)次比较。在最坏状况下则需要O(n^2)次 102 | 比较,但这种状况并不常见。事实上,快速排序通常明显比其他O(nlogn)算法 103 | 更快,因为它的内部循环可以在大部分的架构上很有效率地被实现出来。 104 | */ 105 | void QuickSort(int* A, int left, int right) 106 | { 107 | if (left >= right) 108 | return; 109 | int pivot_index = Partition(A, left, right); // 基准的索引 110 | QuickSort(A, left, pivot_index - 1); 111 | QuickSort(A, pivot_index + 1, right); 112 | } 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /排序/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/排序/targetver.h -------------------------------------------------------------------------------- /排序/排序.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 32 | 33 | 源文件 34 | 35 | 36 | 源文件 37 | 38 | 39 | 源文件 40 | 41 | 42 | 源文件 43 | 44 | 45 | 源文件 46 | 47 | 48 | 源文件 49 | 50 | 51 | 52 | 53 | 资源文件 54 | 55 | 56 | -------------------------------------------------------------------------------- /排序/算法复杂度表格.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/landbroken/BasicKnowledge/77b2ee482b1648c14b75bfa0971a08d91286d3e3/排序/算法复杂度表格.png --------------------------------------------------------------------------------