![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
不叫芫荽
这个作者很懒,什么都没留下…
展开
-
507. 完美数
对于一个 正整数,如果它和除了它自身以外的所有 正因子 之和相等,我们称它为 「完美数」。 给定一个 整数 n, 如果是完美数,返回 true,否则返回 false 示例 1: 输入:28 输出:True 解释:28 = 1 + 2 + 4 + 7 + 14 1, 2, 4, 7, 和 14 是 28 的所有正因子。 示例 2: 输入:num = 6 输出:true 示例 3: 输入:num = 496 输出:true 示例 4: 输入:num = 8128 输出:true class Soluti原创 2021-01-10 15:29:30 · 98 阅读 · 0 评论 -
归并排序
代码: #include<iostream> using namespace std; class List{ public: List(){ array=NULL; } void creat(){ int n; cout<<"请输入数组大小:"; cin>>n; this->n=n; array=new int[n]; for(int i=0;i<n;i++){ cin>>arra原创 2021-01-09 01:40:26 · 84 阅读 · 0 评论 -
选择排序
1.简单选择排序 #include<iostream> using namespace std; class List{ public: List(){ array=NULL; } void creat(){ int n; cout<<"请输入数组大小:"; cin>>n; this->n=n; array=new int[n]; for(int i=0;i<n;i++){ cin>>原创 2021-01-09 01:03:04 · 62 阅读 · 0 评论 -
交换排序
1.冒泡排序 代码: #include<iostream> using namespace std; class List{ public: List(){ array=NULL; } void creat(){ int n; cout<<"请输入数组大小:"; cin>>n; this->n=n; array=new int[n]; for(int i=0;i<n;i++){ cin>&原创 2021-01-09 00:14:53 · 67 阅读 · 0 评论 -
排序算法
写了一个很神奇的排序,从0到i-1开始比较,遇到比下标i大的数就交换,这样一趟比较下来,和直接插入排序的一趟比较是一样的 感觉像是直接插入排序和冒泡排序的结合 void sort(){ for(int i=1;i<size;i++){ for(int j=0;j<i;j++){ if(array[j]>array[i]){ int t=array[j]; array[j]=array[i]; array[i]=t; }原创 2021-01-08 23:32:49 · 61 阅读 · 0 评论 -
插入排序
1.直接插入排序 思路:从i开始遍历,i之前为已经排序好的数组,从0至i-1遍历,如果遇到比i小的数字,就交换 代码: #include<iostream> using namespace std; class List{ public: List(){ array=NULL; } void creat(){ int n; cout<<"请输入数组大小:"; cin>>n; this->n=n; array=new原创 2021-01-08 22:40:02 · 96 阅读 · 0 评论