![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
captionyao
这个作者很懒,什么都没留下…
展开
-
递归汉诺塔
#include <iostream>#include <string>using namespace std;void process(int n,string from,string to,string help){ if(n==1){ cout<<"Move 1 "<<"from"<<from<...原创 2020-02-19 19:07:34 · 205 阅读 · 0 评论 -
二叉树的后继节点
后继节点:就是一个节点在中序遍历中的下一个节点。在中序遍历中,如果该节点有右子树,该节点的后继节点,就是再二叉树中,该节点的右子树中,最左的节点。当x节点没有右子树,就去查找x是哪个节点的左子树。...原创 2020-02-15 13:28:48 · 1425 阅读 · 0 评论 -
二叉树的非递归遍历
中序遍历:当前节点不为空,就把当前节点压栈。然后走当前节点的左节点。当前节点为空,把栈的top()拿出来,并将top()赋值为当前节点。然后,走当前节点的右节点。...原创 2020-02-13 20:59:08 · 81 阅读 · 0 评论 -
二叉树的递归遍历
#include <stdio.h>#include <stdlib.h>#include <iostream>#include <stack>using namespace std;typedef struct node { int data; struct node* left; struct node* r...原创 2020-02-13 16:52:01 · 80 阅读 · 0 评论 -
判断一个单链表是否有环以及判断两个单链表是否相交
判断一个单链表是否有环:方法1:使用hash_map,当map中出现重复的值时,该值即为环的第一个节点。方法2:两个指针,快指针一次走两步,慢指针一次走一步,当快慢指针相遇时,将快指针放于head位置,快指针由一次走两步变成一次走一步,快指针和慢指针一定会在第一个入环节点处相遇。。判断两个链表是否相交:方法1:使用map,将链表1全部加入map中,然后依次查找...原创 2020-02-13 12:13:23 · 178 阅读 · 0 评论 -
c++ hash_map用法总结
c++ STL库里有自定义的hash_map 方法,但是使用起来并不是那么方便hash_map主要的方法有find(),insert()我结合官方API说明一下他们的用法一、需要特别注意的地方,1.头文件的引用2.如何插入一个<key,value>键值对(参考一下代码)3.find()的返回值4.如何获取某一个key值相应的value值hm1_R...转载 2020-02-13 10:49:22 · 2515 阅读 · 0 评论 -
在一个已排序的二维数组中,找到指定数字的位置
在一个已排序的二维数组中,找到指定数字的位置二维数组排序规则:列从上到小依次增加,行从左到右以此增加/*给定一个有N*M的整型矩阵matrix和一个整数K, matrix的每一行和每一 列都是排好序的。实现一个函数,判断K 是否在matrix中。*/#include <iostream>using namespace std;int main(){ in...原创 2020-02-12 16:29:53 · 894 阅读 · 0 评论 -
c++STL中优先队列的使用
优先队列即为,堆说到队列,我们首先想到就是先进先出,后进后出;那么何为优先队列呢,在优先队列中,元素被赋予优先级,当访问元素时,具有最高级优先级的元素先被访问。即优先队列具有最高级先出的行为特征。优先队列在头文件#include <queue>中;其声明格式为:priority_queue <int> ans;//声明一个名为ans的整形的优先队列基本...转载 2020-02-08 16:59:17 · 138 阅读 · 0 评论 -
大数乘法
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include<stdlib.h>#include<string.h>//C语言声明变量需要加上stuct//C语言结构内部不可以有函数//C语言结构体没有公有,私有,继承struct MyStruct{ int num1; int ...原创 2020-02-08 16:44:00 · 79 阅读 · 0 评论 -
简单的比较器
#include <iostream>#include <algorithm>using namespace std;int a[1001];bool cmp(int a,int b){ return a>b;}int main(){ int n; cin>>n; for(int i=0;i<n;...原创 2020-02-08 16:26:03 · 197 阅读 · 0 评论 -
荷兰国旗
#include <iostream>using namespace std;int a[100];void swap_t(int a[],int l,int i){ int t=a[l]; a[l]=a[i]; a[i]=t;}void p_sort(int *a,int n,int num){ int l=-1,m=n; ...原创 2020-02-08 16:24:08 · 162 阅读 · 0 评论 -
普通快排
参考链接 :http://blog.sina.com.cn/s/blog_5c5bc9070100y4zv.html#include <iostream>#include <stdlib.h>#include <time.h>#include <bits/stdc++.h>using namespace std;int a[10000...原创 2020-02-08 16:23:41 · 187 阅读 · 0 评论 -
冒泡排序
#include <iostream>using namespace std;//exchange the 2 items a and bvoid swap(int &a, int &b){ a = a + b; b = a - b; a = a - b;}//ergodic the buf and print itvoid ...原创 2020-02-08 16:09:43 · 92 阅读 · 0 评论