自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(20)
  • 收藏
  • 关注

原创 优先队列算法

#include<iostream>#include<vector>#include<algorithm>#include<queue>using namespace std;int main(){ int n, k; cin >> n >> k; priority_queue<int, vector<int>, less<int>> qu; int start; cin &g.

2021-08-07 18:01:26 61

原创 strcpy的实现

char* strcpy(char* strDest, const char* strSrc){ if(strDest == NULL || strSrc == NULL) return NULL; if(strDest == strSrc) return strDest; char* tempStr = strDest; //记录字符串头指针 while((*strDest++ = *strSrc++) != '\0'); return tempStr; }...

2021-07-27 12:44:35 51

原创 哈夫曼编码

#include<iostream>#include<string>#include<vector>#include<algorithm>using namespace std;struct HuffmanTree { char val; int weight; struct HuffmanTree* left; struct HuffmanTree* right;};//虚函数class condition {public: .

2021-07-26 11:08:11 58

原创 图的相关算法:拓扑排序和关键路径

拓扑排序#include<iostream>#include<vector>#include<stack>#include<string>using namespace std;struct EdgeNode { int adjvex; //int weight; struct EdgeNode* next;};struct VextexNode { int in; int name; EdgeNode* firstedge;

2021-07-26 11:04:08 82

原创 鸡蛋掉落问题

class Solution {public: int superEggDrop(int k, int n) { vector<vector<int>>dp(n+1,vector<int>(k+1,INT_MAX)); //1个鸡蛋,n层楼,最坏都需要n次。 for(int i=1;i<=n;i++) { dp[i][1]=i; } .

2021-07-25 20:17:41 42

原创 类的继承实例

#include<iostream>#include<string>using namespace std;class Person {private: string name; int age; string sex;public: Person() :name("李四"), age(18), sex("man") {} Person(string c_name, int c_age, string c_sex) :name(c_name), age(.

2021-07-25 16:44:40 116

原创 最大公约数和快速幂运算

最大公约数 int measure(int x, int y){ int z = y; while(x%y!=0) { z = x%y; x = y; y = z; } return z;} 实现pow(x,n),即计算 x 的 n 次幂函数(即,xn) class Solution {public: double Pow(double x,unsigned int n) { double ret = 1; ...

2021-07-25 15:25:29 84

原创 链表相关问题

反转链表 class Solution {public: ListNode* reverseList(ListNode* head) { //迭代 // ListNode*pre = NULL,*current=head; // while(current) // { // ListNode* next = current->next; // current-&..

2021-07-25 11:11:10 32

原创 大数相加与相乘

大数相加 class Solution {public: string addStrings(string num1, string num2) { int i = num1.length() - 1, j = num2.length() - 1, add = 0; string ans = ""; while (i >= 0 || j >= 0 || add != 0) { int x = i >..

2021-07-25 10:39:09 57

原创 旋转数组相关问题

旋转数组最小数字 class Solution {public: int minArray(vector<int>& numbers) { int len = numbers.size(); int l = 0, r=len-1; while(l<=r) { int m = l + (r-l)/2; if(numbers[m] < n..

2021-07-25 10:25:04 42

原创 回溯相关问题解法

不包含重复元素的子集问题 class Solution {public: vector<int>t; vector<vector<int>>ret; vector<vector<int>> subsets(vector<int>& nums) { vector<int>temp; vector<vector<int>>..

2021-07-25 10:08:38 113

原创 后缀表达式

#include<iostream>#include<stack>#include<set>using namespace std;string TurnLater(string str) //转换为后缀表达式{ string ret; stack<char>sign; int len = 0; for (int i = 0; i < str.size(); i++) { if (isdigit(str[i])) { .

2021-07-23 21:06:00 46

原创 字符串处理相关题目

无重复字符的最长子串 int lengthOfLongestSubstring(string s) { int len = s.size(); if(len <= 1) return len; int MAX=INT_MIN; bool flag[256]={0}; int begin=0,end=0; for(int i = 0;i<len;i++) ..

2021-07-23 20:08:51 73

原创 单例模式的写法

单例模式:作用:保证一个类仅有一个实例,并提供一个访问它的全局访问点。//懒汉式class Single {private: static Single instance; Single(){}public: static Single getInstance() { if (instance == NULL) instance = new Single(); return instance; }};//饿汉式class Single {private:

2021-07-12 11:13:06 45

原创 字符串匹配(KMP)算法

#include<iostream>#include<vector>#include<string>using namespace std;void get_nextval(string t, vector<int>& nextval){ int i = 0; int j = -1; nextval[0] = -1; while (i < t.size() - 1) { if (j == -1 || t[i] == t.

2021-07-12 10:24:12 36

原创 二叉树相关算法

求二叉树的深度 int maxDepth(TreeNode* root) { if (root == NULL) return 0; int left = maxDepth(root->left) + 1; int right = maxDepth(root->right) + 1; return max(left, right); } 二叉树是否对称 bool Istrue(TreeNode*...

2021-07-12 10:07:42 55

原创 图相关算法-最短路径

迪杰斯特拉算法(D算法)#include<iostream>#include<vector>#include<limits>using namespace std;void ShortestPath_Dijkstra(vector<vector<int>>& arc, int numVex, vector<int>& Patharc, vector<int>& ShortPath){

2021-07-02 16:21:13 55

原创 图相关算法:最小生成树

P算法(基于点) #include<iostream>#include<vector>#include<limits>using namespace std;int MiniSpanTree_Prim(int numVex, vector<vector<int>>arc){ int sum = 0; vector<int>adjvex(numVex); vector<int>lower(nu..

2021-06-29 19:56:56 68

原创 图的遍历算法

邻接矩阵的DFS和BFS #include<iostream>#include<vector>#include<queue>#define MAXVEX 100using namespace std;struct MGraph { int numV; int numE; char vexs[MAXVEX]; int arc[MAXVEX][MAXVEX];};void DFS(MGraph* G, int index, vector..

2021-06-28 19:14:07 53

原创 常用排序算法

冒泡排序原理:一种交换排序,基本思想是两两比较相邻记录的关键字,如果反序则交换,直到没有反序的记录为止。 代码: #include<iostream>#include<vector>#include<algorithm>using namespace std;int main(){ char c; int num; vector<int>array; do { cin >> num; array.push_b.

2021-06-24 23:16:46 58

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除