- 博客(20)
- 收藏
- 关注
原创 快排
#include <iostream> #include <vector> using namespace std; void Swap(int &a,int &b) { int tmp = a; a = b; b = tmp; } void Show(vector<int> & vec) { vector<int> :: iterator it = vec.begin(); for(
2020-07-27 23:11:02 124
原创 希尔排序
#include <iostream> #include <vector> using namespace std; void Swap(int &a,int &b) { int tmp = a; a = b; b = tmp; } void Show(vector<int> & vec) { vector<int> :: iterator it = vec.begin(); for(
2020-07-27 23:09:15 99
原创 直接插入排序
#include <iostream> #include <vector> using namespace std; void Swap(int &a,int &b) { int tmp = a; a = b; b = tmp; } void Show(vector<int> & vec) { vector<int> :: iterator it = vec.begin(); for(
2020-07-27 23:06:39 103
原创 选择排序
#include <iostream> #include <vector> using namespace std; void Swap(int &a,int &b) { int tmp = a; a = b; b = tmp; } void Show(vector<int> & vec) { vector<int> :: iterator it = vec.begin(); for(
2020-07-27 23:04:12 100
原创 冒泡排序
#include <iostream> #include <vector> using namespace std; void Swap(int &a,int &b) { int tmp = a; a = b; b = tmp; } void Show(vector<int> & vec) { vector<int> :: iterator it = vec.begin(); for(
2020-07-27 23:02:09 110
原创 打家劫舍(三光)
没啥好说的,嗯,就是那个啥动态规划,对就是动态规划。 class Solution { public: int rob(vector<int>& nums) { int n = nums.size(); vector<int> dp(n); dp[0] = nums[0]; dp[1] = max(nums[0],nums[1]); for(int i = 2;i < n;++i)
2020-07-23 22:13:44 122
原创 二叉树的中序遍历(递归和非递归)
非递归: 在这class Solution { public: vector<int> inorderTraversal(TreeNode* root) { vector<int> vec; stack <TreeNode*> sta; TreeNode* ptr = root; while(NULL != ptr || !sta.empty()) {
2020-07-23 21:14:25 107
原创 不同的二叉搜索树
好吧我是懒狗,看到这个题,第一反应就是,递归去做,这个题也没给时间限制,我就试了一下递归。 int numTrees(int n) { int sum = 0; if(n == 1 || n == 0) { return 1; } for(int i = 1;i <= n;++i) { sum +=numTrees(i-1) * numTrees(n - i); } return sum; } 大概就
2020-07-22 23:11:44 159
原创 力扣——两数之和(简单)
#include<iostream> using namespace std; void Sum(int *nums,int target,int len,int &f1,int &f2) { if(NULL == nums)return ; for(int i = 0;i < len;++i) { for(int j = i+1;j < len;++j) { if(nums[i.
2020-07-21 22:26:41 524
原创 工厂模式
简单工厂模式: #include<iostream> using namespace std; class Fruits { public: Fruits(const string &name) :nname(name){} virtual void Show() = 0; private: string nname; }; class Apple: public Fruits { public: Apple(const st
2020-07-20 22:09:18 108
原创 不能被继承的类
#include<iostream> /* 通过友缘和虚继承实现。 在继承层次中,先构造虚基类,可是虚基类A,只能由B来进行构造,也就是说B这个类不能被继承 注意B的声明必须放到A的前面。 */ using namespace std; class B; class A { private: A() {}; friend class B; }; class B : virtual public A { public: B():A() {} };
2020-07-20 22:05:20 182
原创 单例模式
饿汉模式 /* #include<iostream> using namespace std; class Test { public: static Test* Getinstance()//只能以指针返回,其他不行。static调用约定不是thiscall { return m_instance; } private: Test()//将构造和拷贝构造写在私有下 {}; Test(const Test & r
2020-07-16 22:05:29 89
原创 最短路径——Floyd算法
#include<iostream> using namespace std; typedef char VertexType; typedef int EdgeType; const int MAXVEX = 100; const int INFINITY = 65535; typedef int Pathmatirx[MAXVEX][MAXVEX]; typedef int ShortPathTable[MAXVEX][MAXVEX]; typedef str
2020-07-14 09:22:31 134
原创 BST——C++
BST树,是指左子树上所有节点都小于双亲结点,右子树上所有节点都大于双亲结点的二叉树,BST树又称为二叉排序树和二叉搜索树,理想状态下真的很不错,如果不是频繁的对树进行增删其实哈、还好,嘻嘻,就怕你改成了斜树,那样就是废品。怎么说呢,这些搜索树,都是为了模仿二分查找的,好好学习吧少年。 #include<iostream> /* BST的类写好了,增删改查,emmm不难,但是发现书上给的代码有问题,大话数据结构324页,4-11行。 错的离谱,感觉就像开玩笑,可能是我看错了,我没按照书上写。
2020-07-13 23:22:29 508
原创 与这个美丽的世界说再见的atoi——使用字符串来判断是否溢出
/* 题目1:(简答题:10.0分) 编程实现将字符串转换为整型数; int my_atoi(const char *str); 1.遇到非数字字母,停止转换; 示例: str = “234.324” ; 返回值是234; 2.首先出现空格的字符串可以转换,转换开始后,遇到空格停止转换; 示例: str =" 342 456"; 返回值是342; 3.可以处理正负号; 示例: str = " +234.bad" ; 返回值是 234; str = " -342ab.234" ; 返回值是:
2020-07-06 00:48:53 330 1
原创 点分十进制表示的字符串转换为 unsigned int 整型数值
/*题目4:(简答题:10.0分) 实现函数将点分十进制表示的字符串转换为 unsigned int 整型数值 unsigned int my_ResDotDec(const char *strip); 参数说明:strip 点分十进制表示的字符串; 示例: strip =“128.11.3.31” ; 返回值: 2148205343; strip =“128.399.2.12” ; 返回值为 UINT_MAX #include <iostream> #include <ctype.h&
2020-07-03 19:12:24 955
原创 无符号整型转点分十进制
/*题目3:(简答题:10.0分) 实现函数将 unsigned int 整型数值转为点分十进制记法表示: 点分十进制(Dotted Decimal Notation)全称为点分(点式)十进制表示法, 是IPv4的IP地址标识方法。 IPv4中用四个字节表示一个IP地址,每个字节按照十进制表示为0~255。 点分十进制就是用4个从0~255的数字,来表示一个IP地址。 char * my_DotDec(unsigned int ip,char *buffer); 参数说明: value:欲转换的数数值。 b
2020-07-03 11:52:28 1597
原创 My——itoa
/*题目2:(简答题:10.0分) 编程实现将整型数值转换为字符串。 char *my_itoa(int value, char *buffer, int radix); 参数说明: value:欲转换的数值。 buffer:目标字符串的地址。 radix:转换后的进制数,可以是2进制,10进制、16进制等。 示例: value = 10; radix = 2; string=“1010” 不考虑value 为负数。 与函数 int sprintf(char *string, char *format ,…
2020-07-03 08:55:31 210
原创 My——atoi(进制,空格,符号,溢出等处理),最全最细,有问题请问我
/* 题目1:(简答题:10.0分) 编程实现将字符串转换为整型数; int my_atoi(const char *str); 1.遇到非数字字母,停止转换; 示例: str = “234.324” ; 返回值是234; 2.首先出现空格的字符串可以转换,转换开始后,遇到空格停止转换; 示例: str =" 342 456"; 返回值是342; 3.可以处理正负号; 示例: str = " +234.bad" ; 返回值是 234; str = " -342ab.234" ; 返回值是:
2020-07-02 23:32:32 589
原创 最短路径(Dijkstra)
#include<iostream> using namespace std; typedef char VertexType; typedef int EdgeType; const int MAXVEX = 100; const int INFINITY = 65535; typedef int Patharc[MAXVEX]; typedef int shortPathTable[MAXVEX]; typedef struct { VertexT
2020-07-01 10:26:38 179
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人