
算法
SmartDemo
加油,努力!
展开
-
排序算法c++实现
【代码】排序算法c++实现。原创 2023-02-23 15:22:24 · 150 阅读 · 0 评论 -
求最大公因子GCD
【代码】求最大公因子GCD。原创 2022-10-28 10:14:37 · 300 阅读 · 0 评论 -
SVD之python代码实现
环:jupyter(tensorflow)其中:mi.png是网上下载的size =(521,396,3)的 人物图片 最终效果:参考:SVD(奇异值分解)Python实现 - EndlessCoding - 博客园 (cnblogs.com)原创 2022-06-20 20:57:38 · 1601 阅读 · 0 评论 -
leetcode987. 二叉树的垂序遍历
#include<iostream>#include<vector>#include<map>#include<algorithm>#include<sstream>#include<queue>using namespace std;struct TreeNode { int val; TreeNode *left; TreeNode *right; TreeNode() : val(.原创 2021-08-09 19:12:42 · 186 阅读 · 0 评论 -
递归判断是否二叉平衡树
可以说是相当简洁粗暴了。#include<iostream>#include<algorithm>using namespace std;struct Node{ int val; Node *left,*right; Node(int x):val(x),left(NULL),right(NULL){}};int height(Node* root){ if(root == NULL) return 0; return ma.原创 2020-12-22 01:31:55 · 236 阅读 · 0 评论 -
反转相邻链表单元
#include<iostream>using namespace std;struct Node { int val; Node* next; Node() :val(0), next(NULL) {} Node(int v) :val(v), next(NULL) {}};Node* reverseNeighbor(Node* head) { Node* dummy = new Node(); dummy->next = h.原创 2020-10-23 23:14:35 · 261 阅读 · 0 评论 -
反转单链表
#include<iostream>using namespace std;struct Node{ int val; Node* next; Node(int v):val(v),next(NULL){}};Node * reverseList(Node* head){ Node* pre = NULL; Node* cur = head; Node* cnext = NULL; while(cur){ cn.原创 2020-10-23 22:54:43 · 138 阅读 · 0 评论 -
单链表的头插法和尾插法
一、头插法#include<iostream>using namespace std;struct ListNode { int val; ListNode* next; ListNode() : val(0), next(nullptr) {} ListNode(int x) : val(x), next(nullptr) {} ListNode(int x, ListNode* next) : val(x), next(next) {}};ListNode* Ins原创 2020-10-19 19:45:30 · 239 阅读 · 0 评论 -
两种层次遍历的实现
一、第一种#include<iostream>#include<vector>#include<algorithm>using namespace std;struct Node{ Node* left; Node* right; int val; Node(int v):left(nullptr),right(nullptr),val(v){} Node(Node* l,Node* r,int v):left(l)原创 2020-10-19 12:08:54 · 319 阅读 · 0 评论 -
c++之——Combination(排列) && Permutation(组合)
一、排列#include<iostream>#include<vector>using namespace std;class Solution{private: int n; vector<vector<int>> ans; vector<int> vis;public: void dfs1(vector<int> &nums,vector<int>&c).原创 2020-10-10 15:20:37 · 679 阅读 · 0 评论 -
dfs生成迷宫
一、迷宫随机生成算法 : dfsimport numpy as npimport randomfrom matplotlib import pyplot as pltimport matplotlib.cm as cmnum_rows = 10num_cols = 10# M = [L,U,R,D,VIS]M = []r = 0c = 0M = np.zeros((num_rows,num_cols,5),dtype=np.uint8)image = np.zeros((nu原创 2020-10-09 18:36:08 · 770 阅读 · 0 评论 -
python版本---------DFS && BFS
def DFS(graph,s): st = [] st.append(s) seen = set() seen.add(s) while st: vertex = st.pop() #此时栈顶元素出栈 datas = graph[vertex] for data in datas: if data not in seen: seen.add(data) st.append(data) print(vertex)def BFS(grap.原创 2020-10-09 17:48:46 · 169 阅读 · 0 评论 -
morris前序遍历
#include<iostream>#include<vector>#include<sstream>using namespace std; struct Node{ int value; Node* left; Node* right; Node(){value = 0,left = NULL;right = NULL;} Node(int val):value(val),left(NULL),right(NULL).原创 2020-09-22 10:16:24 · 220 阅读 · 0 评论 -
count words of given string && record words of given string
//count the num of words#include<iostream>using namespace std; unsigned countWords(string str) { unsigned int wc = 0; bool flag = true; for(char c:str){ cout<<c<<endl; if(c == ' ' || c == '\t' || c == '\.原创 2020-09-20 13:06:25 · 155 阅读 · 0 评论 -
Alias method
参考链接:python实现:https://lips.cs.princeton.edu/the-alias-method-efficient-sampling-with-many-discrete-outcomes/ 算法思想:https://www.keithschwarz.com/darts-dice-coins/ 思想简单介绍:https://blog.youkuaiyun.com/qq_33765907/article/details/79182355 各版本代码实现:https://blog.csd原创 2020-09-17 23:50:14 · 242 阅读 · 0 评论 -
C++实现_topk排序
一、topk_堆排#include<iostream>#include<vector>#include<algorithm>//堆排序using namespace std;void Swap(vector<int>& tree, int a, int b) { int temp = tree[a]; tree[a] = tree[b]; tree[b] = temp;}void heapify(vector<int.原创 2020-07-25 00:40:04 · 928 阅读 · 0 评论 -
c++实现_链表反转
#include<iostream>using namespace std;struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}}; class Solution {public: ListNode* reverseList(ListNode* l) { ListNode* pre = NULL, * temp = NU.原创 2020-07-23 12:20:27 · 266 阅读 · 0 评论 -
c++实现_分段树
#include<iostream>#define MAX_LEN 1000using namespace std;//int node = 0:从根节点开始建树void buid_tree(int arr[], int tree[], int node, int start, int end) { if (start == end) { tree[node] = arr[start]; } else { int left_node = 2 * node + 1; .原创 2020-07-17 10:32:31 · 382 阅读 · 0 评论 -
c++实现_堆排序
#include<iostream>using namespace std;//堆满足两个要求://1、完全二叉树//2、parent>childvoid swap(int tree[],int i, int j) { int temp = tree[i]; tree[i] = tree[j]; tree[j] = temp;}void heapify(int tree[], int n,int i){ if (i >= n) return; int .原创 2020-07-17 10:30:50 · 159 阅读 · 0 评论 -
c++实现_Kruskal算法(最小生成树算法)
#include<iostream>#include<vector>#include<algorithm>using namespace std;typedef pair<int, int> iPair;struct Graph { int V, E;//V:the number of the vertices //E:the number of edges vector<pair<int, iPair>> e.原创 2020-07-07 11:58:30 · 371 阅读 · 0 评论