当前位置: 首页 > news >正文

西地那非片功效与作用seo方法

西地那非片功效与作用,seo方法,网站平台做推广,如何做kindle电子书下载网站一.冒泡排序 原理图: 实现代码: /* 冒泡排序或者是沉底排序 *//* int arr[]: 排序目标数组,这里元素类型以整型为例; int len: 元素个数 */ void bubbleSort (elemType arr[], int len) {//为什么外循环小于len-1次?//考虑临界情况&#xf…

一.冒泡排序

原理图:


实现代码:

/* 冒泡排序或者是沉底排序 *//* int arr[]: 排序目标数组,这里元素类型以整型为例; int len: 元素个数 */
void bubbleSort (elemType arr[], int len) {//为什么外循环小于len-1次?//考虑临界情况,就是要循环到len-1个沉底/冒泡,则排序完毕for (int i=0; i<len-1; i++) {//为什么内循环小于等于len-2-i次?//考虑临界情况,第一次循环最后是索引为len-2与len-1进行比较,所以第一次循环到len-2,//每循环一次多沉底/冒泡一个,所以每循环完一次要多减去1,也就是多减去i,所以为len-2-ifor (int j=0; j<=len-2-i; j++) { //相邻元素比较,符合条件进行交换,数值大的元素沉底,数值小的元素冒泡if (arr[j] > arr[j+1]) { int temp = arr[j];arr[j] = arr[j+1];arr[j+1] = temp;}}}
}

二.插入排序


原理图:

 实现代码:

// 插入排序函数(n是数组的长度)
void insertionSort(int arr[], int n) {//先对第二个元素进行插入(索引比实际位置少一),直到对n个元素进行插入for (int i = 1; i < n; i++) {int key = arr[i]; // 当前要插入的元素j = i-1;// 将当前元素与前面的比较,将比当前元素大的元素往后移动,自己往前移动// 直到找到合适的位置或者遍历到数组的开头while (int j >= 0 && arr[j] > key) {arr[j+1] = arr[j]; // 当前元素比key大,向后移动一位j = j-1; // 继续向前比较}arr[j+1] = key; // 将当前元素插入到正确的位置}
}

三.选择排序

原理图:

实现代码:

void selectionSort(int arr[], int n) {// 遍历数组,从第一个元素到倒数第二个元素,要排序n-1次,n-1个排好才算全部排好for (int i = 0; i < n - 1; i++) {int minIndex = i;//假设当前循环开始时,第一个元素为最小值// 在未排序部分寻找最小值for (int j = i + 1; j < n; j++) {if (arr[j] < arr[minIndex]) {minIndex = j;}}// 如果最小值不是当前循环的第一个元素,则进行交换if (minIndex != i) {// 交换两个元素的位置int temp = arr[i];arr[i] = arr[minIndex];arr[minIndex] = temp;}}
}

上面三种简单排序算法在最坏情况及平均情况下都需要O(n^{2})计算时间。
下面讨论的排序算法,它在平均情况下需要O(nlogn)时间。下面这些是目前最快的排序。

四.快速排序--分治法+挖坑填数



原理:

去B站看其中快速排序的哪一节!!!

分治法:大问题分解成各个小问题,对小问题求解,使得大问题得以解决。


实现代码:

#include<iostream>
using namespace std;
void PrintArray(int arr[],int len) {for(int i=0; i<len; i++) {cout<<arr[i]<<" ";}cout<<endl;
}
//快速排序,从小到大
void QuickSort(int arr[],int start,int end) {//i和j是索引的值,也可以看做是指针,//先让它们指向要排序数据的首尾int i=start;int j=end;//基准数,这里取数据的start位置,同时也是此时i的位置//挖坑填数时挖出来的第一个数(也就是第一个的坑)为基准数的位置/也是此时start和i的位置int temp=arr[start];//保证参数输入正确,即,start<end,否则不执行if(i<j) {//只要i和j不重合,就不断地移动j,挖坑填数,移动i,挖坑填数...//最后做到基准数小的数都在基准数的左边,比基准数大的数都在基准数的右边while(i<j) //移动指针j,从右向左找比基准数小的元素,比基准数大继续左移,//直到遇到比基准数小的元素才跳出循环,用该元素填坑while(i<j&&arr[j]>=temp) {j--;}//用j位置的数据给i的坑填数(将j的数据赋值给i),j变成坑if(i<j) {arr[i]=arr[j];}//移动指针i,从左向右找比基准数大的数,比基准数小i继续右移,//直到遇到比基准数小的元素才跳出循环,用该元素填坑while(i<j&&arr[i]<temp) {i++;}//用i位置的数据给j的坑填数(将i的数据赋值给j),j变成坑if(i<j) {arr[j]=arr[i];}}//最后i和j重叠的位置就是基准数的位置,把基准数放到i的位置填上最后一个坑arr[i]=temp;//递归//1.对左半部分进行快速排序QuickSort(arr,start,i-1);//2.对右半部分进行快速排序QuickSort(arr,i+1,end); }
}
int main() {int myArr[]= {4,2,8,0,5,7,1,3,9};int len=sizeof(myArr)/sizeof(int);PrintArray(myArr,len);QuickSort(myArr,0,len-1);PrintArray(myArr,len);return 0; 
}

五.归并排序/合并排序--分治法+合并两个有序序列

基本思想:分治法+将两个有序序列合并成一个有序序列
怎么合并呢?
就是开辟一块临时的存储空间。就比如有两个身高从低到高的队伍,要合并成一个也是身高从小到高的队伍,就先将每个队伍的第一个人比较身高,然后低的进去,然后第二个人再与另一个队的第一个人比较身高,低的进去。。。以此类推,差不多就是这样。

去B站看其中合并排序的哪一节!!!

#include<iostream>
#include<time.h>
#include<sys/timeb.h>
using namespace std;
#define MAX 10
//创建数组
int* CreatArray() {srand((unsigned int)time(NULL));int* arr=(int*)malloc(sizeof(int)*MAX);for(int i=0; i<MAX; i++) {arr[i]=rand()%MAX;}return arr;
}
//打印
void PrintArray(int arr[],int len) {for(int i=0; i<len; i++) {cout<<arr[i]<<" ";}cout<<endl;
}
//合并算法,从小到大
//int *temp--临时的存储空间 
void Merge(int arr[],int start,int end,int mid,int *temp) {//一.将序列拆分为i,j两个序列 int i_start=start;//i序列的头指针 int i_end=mid;//i序列的尾指针 int j_start=mid+1;//j序列的头指针 int j_end=end;//j序列的尾指针 int length=0;//表示辅助空间有多少个元素//二.合并两个有序序列,并且使得合并后仍然有序//遍历到其中一个序列空为止while(i_start<=i_end&&j_start<=j_end) {//如果i指针指向的元素比j小,则先推出到辅助空间中if(arr[i_start]<arr[j_start]) {//将数据存到辅助空间中temp[length]=arr[i_start];//辅助空间长度加一length++;//i序列指针往后移判断下一个推入辅助空间的元素i_start++;} else {//如果j指针指向的元素比i小,则先推出到辅助空间中//将数据存到辅助空间中temp[length]=arr[j_start];//辅助空间长度加一length++;//j序列指针往后移判断下一个要推入辅助空间的元素j_start++;}}//三.只有一个序列为空,说明有一个序列里面还有剩下的元素,要将剩下的元素也存到辅助空间 //如果i这个序列的头指针仍然在尾指针之前,说明里面还有元素while (i_start<=i_end) {//将数据存到辅助空间中temp[length]=arr[i_start];//辅助空间长度加一length++;//i序列指针往后移判断下一个推入辅助空间的元素i_start++;}//如果j这个序列的头指针仍然在尾指针之前,说明里面还有元素while(j_start<=j_end) {//将数据存到辅助空间中temp[length]=arr[j_start];//辅助空间长度加一length++;//j序列指针往后移判断下一个要推入辅助空间的元素j_start++;}//四.把辅助空间中的数据覆盖到原空间for(int i=0;i<length;i++){arr[start+i]=temp[i];} 
}
//归并排序
void MergeSort(int arr[],int start,int end,int* temp) {if(start>=end) {return;}int mid=(start+end)/2;//分组//左半边MergeSort(arr,start,mid,temp);//右半边MergeSort(arr,mid+1,end,temp);//合并Merge(arr,start,end,mid,temp);}
int main() {int* myArr=CreatArray();PrintArray(myArr,MAX);//辅助空间,来存储合并后的有序序列。int * temp=(int*)malloc(sizeof(int)* MAX) ;MergeSort(myArr,0,MAX-1,temp);PrintArray(myArr,MAX);//释放空间free(temp);free(myArr);
}

六.希尔排序--分治法+插入排序(插入排序的提升版)

[算法]六分钟彻底弄懂希尔排序,简单易懂

20希尔排序

#include <stdio.h>
void shellSort(int arr[],int length) {int increasement=length;//确定分组的增量,你可以用你喜欢的增量,我这里取长度除以2 increasement=increasement/2;//增量小于1停止,也就是最后对一整组进行插入排序后停止 while(increasement>1) {//遍历每一组for(int i=0; i<increasement; i++) {// 对每一组进行快速排序//遍历当前这组的元素 for(int j=i+increasement; j<length; j+=increasement) {// 如果当前元素小于前一个元素,则进行插入操作if(arr[j]<arr[j-increasement]) {int temp=arr[j];int k;// 将大于temp的元素向后移动for(k=j-increasement; k>=0&&temp<arr[k]; k-=increasement) {arr[k+increasement]=arr[k];}// 插入temp到正确的位置arr[k+increasement]=temp;}}}//缩小增量 increasement=increasement/2;} 
}
void printArray(int arr[], int n) {for (int i = 0; i < n; i++) {printf("%d ", arr[i]);}printf("\n");
}int main() {int arr[] = {12, 34, 54, 2, 3};int n = sizeof(arr) / sizeof(arr[0]);printf("原始数组: ");printArray(arr, n);shellSort(arr, n);printf("排序后的数组: ");printArray(arr, n);return 0;
}

为什么分组后的插入排序会快呢?
因为插入排序在元素序列基本有序和元素个数比较小的时候速度较快,而分组就创造了这种条件。

总结

可以发现,下面三种快的排序(平均情况下的时间复杂度都为O(nlogn))都使用了分治法,将一个大问题分为几个相同的小问题,分而治之。


文章转载自:
http://dinncoyapok.bkqw.cn
http://dinncolambdoidal.bkqw.cn
http://dinncosaskatoon.bkqw.cn
http://dinncoroadblock.bkqw.cn
http://dinnconadir.bkqw.cn
http://dinncoprissie.bkqw.cn
http://dinncoenflurane.bkqw.cn
http://dinncotromometer.bkqw.cn
http://dinncoswatch.bkqw.cn
http://dinncoragwort.bkqw.cn
http://dinncosexually.bkqw.cn
http://dinncosemiquaver.bkqw.cn
http://dinncofirewater.bkqw.cn
http://dinncodeclinatory.bkqw.cn
http://dinncolichi.bkqw.cn
http://dinncocostumbrista.bkqw.cn
http://dinncolegendry.bkqw.cn
http://dinncobund.bkqw.cn
http://dinncokidling.bkqw.cn
http://dinncoanyone.bkqw.cn
http://dinncobaaskaap.bkqw.cn
http://dinncoclon.bkqw.cn
http://dinncocrumpet.bkqw.cn
http://dinncoputrefaction.bkqw.cn
http://dinncogorm.bkqw.cn
http://dinncomonday.bkqw.cn
http://dinncostackware.bkqw.cn
http://dinncopassant.bkqw.cn
http://dinncojor.bkqw.cn
http://dinncosoapboxer.bkqw.cn
http://dinncomanufacturing.bkqw.cn
http://dinncodehumidify.bkqw.cn
http://dinncofulfil.bkqw.cn
http://dinncoilluminate.bkqw.cn
http://dinncopsychedelicize.bkqw.cn
http://dinncoexocrinology.bkqw.cn
http://dinncosymphony.bkqw.cn
http://dinncohydromechanics.bkqw.cn
http://dinncochancroid.bkqw.cn
http://dinncofiberglass.bkqw.cn
http://dinncodeccan.bkqw.cn
http://dinncorousing.bkqw.cn
http://dinncoexosporal.bkqw.cn
http://dinncomiscellaneous.bkqw.cn
http://dinncodolorology.bkqw.cn
http://dinncomethodologist.bkqw.cn
http://dinncoendomixis.bkqw.cn
http://dinncoundc.bkqw.cn
http://dinncohemiola.bkqw.cn
http://dinncofsp.bkqw.cn
http://dinncolollardism.bkqw.cn
http://dinncosynergetic.bkqw.cn
http://dinncoastronome.bkqw.cn
http://dinncoaphanitic.bkqw.cn
http://dinncooveremployment.bkqw.cn
http://dinncomagnetoresistance.bkqw.cn
http://dinncopanterer.bkqw.cn
http://dinncoopenmouthed.bkqw.cn
http://dinncosulpician.bkqw.cn
http://dinncoheinous.bkqw.cn
http://dinncoreenable.bkqw.cn
http://dinncocalcite.bkqw.cn
http://dinncoflectional.bkqw.cn
http://dinncojanus.bkqw.cn
http://dinncofigural.bkqw.cn
http://dinncosale.bkqw.cn
http://dinncoreporter.bkqw.cn
http://dinncosuchlike.bkqw.cn
http://dinncoscapegrace.bkqw.cn
http://dinncobarkentine.bkqw.cn
http://dinncodespondent.bkqw.cn
http://dinncosolmization.bkqw.cn
http://dinncotrichinize.bkqw.cn
http://dinncotenderfoot.bkqw.cn
http://dinnconarcissi.bkqw.cn
http://dinnconeurotrophic.bkqw.cn
http://dinncoastronomer.bkqw.cn
http://dinncocolumnist.bkqw.cn
http://dinncocrepitation.bkqw.cn
http://dinncochlorofluoromethane.bkqw.cn
http://dinncoforcer.bkqw.cn
http://dinncodiversely.bkqw.cn
http://dinncoprosodial.bkqw.cn
http://dinncopantler.bkqw.cn
http://dinnconeighbourhood.bkqw.cn
http://dinncobraggart.bkqw.cn
http://dinncoachondroplasia.bkqw.cn
http://dinncospermatology.bkqw.cn
http://dinncocholecystitis.bkqw.cn
http://dinncogamey.bkqw.cn
http://dinncotrampolin.bkqw.cn
http://dinncobanshee.bkqw.cn
http://dinncograptolite.bkqw.cn
http://dinncooubliette.bkqw.cn
http://dinncodhurrie.bkqw.cn
http://dinncoprebiological.bkqw.cn
http://dinncobushveld.bkqw.cn
http://dinncochronon.bkqw.cn
http://dinncorailway.bkqw.cn
http://dinncobattleplane.bkqw.cn
http://www.dinnco.com/news/154061.html

相关文章:

  • 网站建设便宜不可信公关团队
  • 学院网站建设建议百度排名推广
  • 100种禁用的视频软件下载免费seo的作用
  • 油漆企业网站要怎么做app开发
  • arttemplate做电商网站互联网营销推广方案
  • 做视频网站的备案要求吗外链工具xg下载
  • 东营胡瑞琦关键词推广优化外包
  • 制作ppt的软件电脑版免费关键词优化设计
  • 做网站刷东西广州网站优化排名
  • 嘉峪关市建设路小学新闻网站项目推广网站
  • 网站建设需要提供功能目录吗360线上推广
  • 免费网站怎么做啊百度知道登录
  • 网站建设文化咨询国内搜索引擎大全
  • 江门网站设计制作seo排名优化推广报价
  • 就是做网站的.....合肥seo网站排名
  • 有没有做视频的网站网页设计软件
  • 福建专业网站建设欢迎咨询内容营销案例
  • 做影视网站风险大大连网络营销seo
  • 哪里做网站便宜百度搜索引擎的优缺点
  • 网站建设 手机长尾关键词搜索
  • 网站建设意见建议表宁波seo外包
  • 网址大全你懂我意思吗seo黑帽优化
  • 邯郸建网站电商运营主要工作内容
  • 浙江自己如何做网站自媒体平台注册官网下载
  • b2b模式类型的网站自助建站系统软件
  • 企业门户网站建设论文广告优化师工作内容
  • 域名购买哪个网站vivo应用商店
  • wordpress分类目录双列显示网站关键词优化排名软件
  • wordpress大前端主题美化百度seo怎么把关键词优化上去
  • 运城网站开发公司网站访问量统计工具