《C/C++函数与算法(算法独立篇)》 |
版本 |
作者 |
参与者 |
完成日期 |
备注 |
YanlzCC++_Algorithm_V01_1.0 |
严立钻 |
|
2020.01.17 |
|
|
|
|
|
|
++++“C/C++函数与算法(算法独立篇)”:是对“C++C铸就生存利器”的综合探索;C/C++作为万能语言,可以开发嵌入式、物联网,也可以开发游戏(Cocos2dx、UE4);
++++“C/C++函数与算法(算法独立篇)”:定位在一个科普类知识,了解C/C++相关库和算法!
#第一篇:C语言函数 |
#第四篇:算法 |
++D23、排序算法 |
++D23.1、插入排序 |
++++D23.1.1、直接插入排序 |
++++立钻哥哥:直接插入排序是一种最简单的插入排序算法;直接插入算法实现简单,适用于待排序元素较少且基本有序的情况;在元素基本有序时,需要比较的次数和移动的次数很少,因此在这种情况下使用直接插入排序最佳;
//立钻哥哥:直接插入排序算法 #include <stdio.h>
void PrintMyArray(int a[], int n);
void main(){ int a[] = { 27, 44, 18, 77, 23, 89, 100}; int t, i, j, n;
n = sizeof(a)/sizeof(a[0]);
for(i=1; i t = a[i]; for(j=i-1; j>=0&&t; j--){ a[j+1] = a[j]; } a[j+1] = t;
PrintMyArray(a, n); } }
void PrintMyArray(int a[], int n) { ... ... } |
++++D23.1.2、折半插入排序 |
++++立钻哥哥:折半插入排序算法是直接插入排序的改进;它的主要改进在于,在已经有序的集合中使用折半查找法确定带排序元素的插入位置;在找到要插入的位置后,将待排序元素插入到相应的位置;
++++[折半插入排序与直接插入排序的区别]:直接插入排序,从右到左按顺序查找插入的位置;折半插入排序,折半查找算法在有序集合中查找插入的位置;
++++[主要用途]:折半插入排序算法也直接插入排序一样,通常也用于待排序元素的个数较少的情况;如果待排序算法基本有序,则最好采用直接插入排序算法;
//立钻哥哥:折半插入排序算法 #include <stdio.h>
void PrintMyArray(int a[], int n);
void main(){ int a[] = { 56, 77, 81, 98, 28, 53, 11 }; int t, i, j, low, high, mid, n;
n = sizeof(a)/sizeof(a[0]); for(i=1; i t = a[i]; for(low=0, high=i-1; high>=low; ){ mid = (low+high)/2; if(t < a[mid]){ high = mid-1; }else{ low = mid+1; } }
for(j=i-1; j>=low; j--){ a[j+1] = a[j]; }
a[low] = t; PrintMyArray(a, n); } }
void PrintMyArray(int a[], int n){ ... ... } |
++++D23.1.3、希尔排序 |
++++立钻哥哥:希尔排序也属于插入类排序算法;希尔排序通过缩小增量,将待排序元素划分为若干个子序列,分别对各个子序列按照直接插入排序算法进行排序;当增量为1时,待排序元素构成一个子序列,对该序列排序完毕后希尔排序算法结束;
++++[与直接插入排序、折半插入排序的区别]:直接插入排序、折半插入排序;待排序元素构成一个子序列;希尔排序:待排序元素划分为若干个子序列,需要分别对每个子序列进行排序;
++++[主要用途]:希尔排序算法可以使值较小的元素很快向前移动,当待排序元素基本有序时,再使用直接插入排序处理,时间效率会高很多;希尔排序主要用在数据量在5000以下且速度要求并不是很重要的场合;
//立钻哥哥:希尔排序算法 #include <stdio.h>
void MyShellSort(int a[], int length, int delta[], int m); void MyShellInsert(int a[], int length, int c); void MyDispArray(int a[], int length);
void main(){ int a[] = { 43, 56, 78, 92, 43, 21, 31 }; int delta[] = { 4, 2, 1 }, m=3, length=sizeof(a)/sizeof(a[0]);
MyShellSort(a, length, delta, m);
MyDispArray(a, length); }
//对数组中的元素进行一趟希尔排序,c是增量 void MyShellInsert(int a[], int length, int c){ int i, j, t;
//将距离为c的元素作为一个子序列进行排序 for(i=c; i<length; i++){ //如果后者小于前者,则需要移动元素 if(a[i] < a[i-c]){ t = a[i]; for(j = i-c; j>=0 && t; j=j-c){ a[j+c] = a[j]; }
//依次将元素插入到正确的位置 a[j+c] = t; } } }
//希尔排序,每次调用算法ShellInsert,delta是存放增量的数组 void MyShellSort(int a[], int length, int delta[], int m){ int i;
//进行m次希尔插入排序 for(i=0; i MyShellInsert(a, length, delta[i]); MyDispArray(a, length); } }
//输出数组a中的元素 void MyDispArray(int a[], int length){ } |
++D23.2、交换排序 |
++++D23.2.1、冒泡排序 |
++++立钻哥哥:冒泡排序是一种简单的交换类排序算法,它是通过交换相邻的两个数据元素,逐步将待排序序列变成有序序列;它的基本算法思想描述:假设待排序元素有n个,从第1个元素开始,依次交换相邻的两个逆序元素,直到最后一个元素为止;当第1趟排序结束,机会将最大的元素移动到序列的末尾;然后按照以上方法进行第2趟排序,次大的元素将会被移动到序列的倒数第2个位置;依次类推,经过n-1趟排序后,整个元素序列就成了有序的序列;每趟排序过程中,值小的元素向前移动,值大的元素向后移动,就像气泡一样向上升,因此将这种排序方法称为冒泡排序;
++++[主要用途]:冒泡算法实现简单,适用于待排序元素较少且对时间要求不高的场合;
//立钻哥哥:冒泡排序算法 #include <stdio.h>
void MyPrintArray(int a[], int n);
void main(){ int a[] = { 45, 78, 92, 44, 52, 67, 98, 12 }; int i, j, t, n=sizeof(a)/sizeof(a[0]);
for(i=1; i<n; i++){ for(j=0; j<n-i; j++){ if(a[j] > a[j+1]){ t = a[j]; a[j] = a[j+1]; a[j+1] = t; } } MyPrintArray(a, n); } }
void MyPrintArray(int a[], int n){ ... ... } |
++++D23.2.2、快速排序 |
++++立钻哥哥:快速排序是冒泡排序算法的改进,也属于交换类排序算法;快速排序正是将每个部分都以枢轴元素为中心不断地划分元素序列,直到每个序列中的元素只有一个,不能继续划分为止;
++++快速排序算法可以通过递归调用实现,排序的过程其实就是不断地对元素序列进行划分,直到每一个部分不能划分时即完成快速排序;
++++[主要用途]:快速算法是冒泡排序算法的改进,实现比较算法,它主要用在需要对大量数据进行排序的情况,它的时间效率要远高于冒泡排序,在数据量特别大的情况下特别明显;
//立钻哥哥:快速排序算法 #include <stdio.h>
void MyDispArray(int a[], int n); void MyDispArray2(int a[], int n, int pivot, int count); void MyQSort(int a[], int n, int low, int high); void MyQuickSort(int a[], int n); void MyPartition(int a[], int low, int high);
//利用快速排序算法对数组a中的元素排序 void MyQSort(int a[], int n, int low, int high){ int pivot; static count = 1;
//如果元素序列的长度大于1 if(low < high){ //将待排序序列a[low,high]划分为两部分 pivot = MyPartition(a, low, high); count++;
//对左边的子表进行递归排序,pivot是枢轴位置 MyQSort(a, n, low, pivot-1);
//对右边的子表进行递归排序 MyQSort(a, n, pivot+1, high); } }
//对数组a进行快速排序 void MyQuickSort(int a[], int n){ MyQSort(a, n, 0, n-1); }
//对数组a[low, high]的元素进行一趟排序,使枢轴前面的元素小于枢轴元素,枢轴后面的元素大于等于枢轴元素,并返回枢轴位置 int MyPartition(int a[], int low, int high){ int t, pivot;
//将表的第一个元素作为枢轴元素 pivot = a[low]; t = a[low];
//立钻哥哥:从表的两端交替地向中间扫描 while(low < high){ //从表的末端向前扫描 while(low<high && a[high]>=pivot){ high--; }
//将当前high指向的元素保存在low位置 if(low < high){ a[low] = a[high]; low++; }
//从表的始端向后扫描 while(){ low++; }
//将当前low指向的元素保存在high位置 if(low < high){ a[high] = a[low]; high--; }
//将枢轴元素保存在low的位置 a[low] = t; }
//返回枢轴所在位置 return low; }
void MyDispArray2(int a[], int n, int pivot, int count){ ... ... }
void MyDispArray(int a[], int n){ ... ... }
void main(){ int a[] = { 33, 66, 77, 88, 43, 23, 14, 58 }; int n = sizeof(a)/sizeof(a[0]); MyDispArray(a, n);
MyQuickSort(a, n); MyDispArray(a, n); } ++++立钻哥哥:快速算法是冒泡排序算法的改进,实现比较复杂,它主要用在需要对大量数据进行排序的情况,它的时间效率要远高于冒泡排序,在数据量特别大的情况下特别明显; |
++D23.3、选择排序 |
++++D23.3.1、简单选择排序 |
++++立钻哥哥:简单选择排序是一种简单的选择类排序算法,它是通过依次找到待排序元素序列中最小的数据元素,并将其放在序列的最前面,从而使待排序元素序列变为有序序列;它的基本算法思想描述:假设待排序的元素序列有n个,在第一趟排序过程中,从n个元素序列中选择最小的元素,并将其放在元素序列的最前面即第一个位置;在第二趟排序过程中,从剩余的n-1个元素中,选择最小的元素,将其放在第二个位置;依次类推,直到没有待比较的元素,简单选择排序算法结束;
++++[主要用途]:简单选择排序算法实现简单,适用于待排序元素较少且对时间要求不高的场合;
//立钻哥哥:简单选择排序算法 #include <stdio.h>
void MySelectSort(int a[], int n); void MyDispArray(int a[], int n);
void main(){ int a[] = { 34, 56, 78, 92, 35, 68, 12 }; int n = sizeof(a)/sizeof(a[0]);
MySelectSort(a, n); MyDispArray(a, n); }
//简单选择排序 void MySelectSort(int a[], int n){ int i, j, k, t;
//将第i个元素与第i+1...n个元素比较,将最小的元素放在第i个位置 for(i=0; i j = i;
//最小的元素的序号为j for(k=i+1; k if(a[k] < a[j]){ j = k; }
//如果序号i不等于j,则需要将序号i和序号j的元素交换 if(j != i){ t = a[i]; a[i] = a[j]; a[j] = t; }
MyDispArray(a, n); } } }
//输出数组中的元素 void MyDispArray(int a[], int n){ ... ... } |
++++D23.3.2、堆排序 |
【XR游戏开发QQ群:784477094】
立钻哥哥推荐的拓展学习链接(Link_Url) |
++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz/
++++虚拟现实VR资讯: https://blog.csdn.net/VRunSoftYanlz/article/details/89165846
++++HTC_VIVE开发基础:https://blog.csdn.net/VRunSoftYanlz/article/details/81989970
++++Oculus杂谈:https://blog.csdn.net/VRunSoftYanlz/article/details/82469850
++++Oculus安装使用:https://blog.csdn.net/VRunSoftYanlz/article/details/82718982
++++Unity+SteamVR=>VR:https://blog.csdn.net/VRunSoftYanlz/article/details/88809370
++++Unity减少VR晕眩症:https://blog.csdn.net/VRunSoftYanlz/article/details/89115518
++++SteamVR简介:https://blog.csdn.net/VRunSoftYanlz/article/details/86484254
++++SteamVR脚本功能分析:https://blog.csdn.net/VRunSoftYanlz/article/details/86531480
++++SteamVR2.0开发指南:https://blog.csdn.net/VRunSoftYanlz/article/details/86618187
++++SteamVR2.2.0开发指南:https://blog.csdn.net/VRunSoftYanlz/article/details/88784527
++++SteamVR2.2.0快速入门:https://blog.csdn.net/VRunSoftYanlz/article/details/88833579
++++SteamVR2.2.0交互系统:https://blog.csdn.net/VRunSoftYanlz/article/details/89199778
++++SteamVR2.2.0传送机制:https://blog.csdn.net/VRunSoftYanlz/article/details/89390866
++++SteamVR2.2.0教程(一):https://blog.csdn.net/VRunSoftYanlz/article/details/89324067
++++SteamVR2.2.0教程(二):https://blog.csdn.net/VRunSoftYanlz/article/details/89894097
++++SteamVR_Skeleton_Poser:https://blog.csdn.net/VRunSoftYanlz/article/details/89931725
++++SteamVR实战之PMCore:https://blog.csdn.net/VRunSoftYanlz/article/details/89463658
++++SteamVR/Extras:https://blog.csdn.net/VRunSoftYanlz/article/details/86584108
++++SteamVR/Input:https://blog.csdn.net/VRunSoftYanlz/article/details/86601950
++++OpenXR简介:https://blog.csdn.net/VRunSoftYanlz/article/details/85726365
++++VRTK杂谈:https://blog.csdn.net/VRunSoftYanlz/article/details/82562993
++++VRTK快速入门(杂谈):https://blog.csdn.net/VRunSoftYanlz/article/details/82955267
++++VRTK官方示例(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82955410
++++VRTK代码结构(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82780085
++++VRTK(SceneResources):https://blog.csdn.net/VRunSoftYanlz/article/details/82795400
++++VRTK_ControllerEvents:https://blog.csdn.net/VRunSoftYanlz/article/details/83099512
++++VRTK_InteractTouch:https://blog.csdn.net/VRunSoftYanlz/article/details/83120220
++++虚拟现实行业应用:https://blog.csdn.net/VRunSoftYanlz/article/details/88360157
++++Steam平台上的VR:https://blog.csdn.net/VRunSoftYanlz/article/details/88960085
++++Steam平台热销VR:https://blog.csdn.net/VRunSoftYanlz/article/details/89007741
++++VR实验:以太网帧的构成:https://blog.csdn.net/VRunSoftYanlz/article/details/82598140
++++实验四:存储器扩展实验:https://blog.csdn.net/VRunSoftYanlz/article/details/87834434
++++FrameVR示例V0913:https://blog.csdn.net/VRunSoftYanlz/article/details/82808498
++++FrameVR示例V1003:https://blog.csdn.net/VRunSoftYanlz/article/details/83066516
++++SwitchMachineV1022:https://blog.csdn.net/VRunSoftYanlz/article/details/83280886
++++PlaySceneManagerV1022:https://blog.csdn.net/VRunSoftYanlz/article/details/83280886
++++Unity5.x用户手册:https://blog.csdn.net/VRunSoftYanlz/article/details/81712741
++++Unity面试题ABC:https://blog.csdn.net/vrunsoftyanlz/article/details/78630687
++++Unity面试题D:https://blog.csdn.net/VRunSoftYanlz/article/details/78630838
++++Unity面试题E:https://blog.csdn.net/vrunsoftyanlz/article/details/78630913
++++Unity面试题F:https://blog.csdn.net/VRunSoftYanlz/article/details/78630945
++++Cocos2dx面试题:https://blog.csdn.net/VRunSoftYanlz/article/details/78630967
++++禅道[zentao]:https://blog.csdn.net/VRunSoftYanlz/article/details/83964057
++++Lua快速入门篇(Xlua拓展):https://blog.csdn.net/VRunSoftYanlz/article/details/81173818
++++Lua快速入门篇(XLua教程):https://blog.csdn.net/VRunSoftYanlz/article/details/81141502
++++Lua快速入门篇(基础概述):https://blog.csdn.net/VRunSoftYanlz/article/details/81041359
++++框架知识点:https://blog.csdn.net/VRunSoftYanlz/article/details/80862879
++++游戏框架(UI框架夯实篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80781140
++++游戏框架(初探篇):https://blog.csdn.net/VRunSoftYanlz/article/details/80630325
++++.Net框架设计:https://blog.csdn.net/VRunSoftYanlz/article/details/87401225
++++从零开始学架构:https://blog.csdn.net/VRunSoftYanlz/article/details/88095895
++++设计模式简单整理:https://blog.csdn.net/vrunsoftyanlz/article/details/79839641
++++专题:设计模式(精华篇):https://blog.csdn.net/VRunSoftYanlz/article/details/81322678
++++U3D小项目参考:https://blog.csdn.net/vrunsoftyanlz/article/details/80141811
++++Unity小游戏算法分析:https://blog.csdn.net/VRunSoftYanlz/article/details/87908365
++++Unity案例(Vehicle):https://blog.csdn.net/VRunSoftYanlz/article/details/82355876
++++UML类图:https://blog.csdn.net/vrunsoftyanlz/article/details/80289461
++++PowerDesigner简介:https://blog.csdn.net/VRunSoftYanlz/article/details/86500084
++++Unity知识点0001:https://blog.csdn.net/vrunsoftyanlz/article/details/80302012
++++Unity知识点0008:https://blog.csdn.net/VRunSoftYanlz/article/details/81153606
++++U3D_Shader编程(第一篇:快速入门篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80372071
++++U3D_Shader编程(第二篇:基础夯实篇):https://blog.csdn.net/vrunsoftyanlz/article/details/80372628
++++Unity引擎基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78881685
++++Unity面向组件开发:https://blog.csdn.net/vrunsoftyanlz/article/details/78881752
++++Unity物理系统:https://blog.csdn.net/vrunsoftyanlz/article/details/78881879
++++Unity2D平台开发:https://blog.csdn.net/vrunsoftyanlz/article/details/78882034
++++UGUI基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78884693
++++UGUI进阶:https://blog.csdn.net/vrunsoftyanlz/article/details/78884882
++++UGUI综合:https://blog.csdn.net/vrunsoftyanlz/article/details/78885013
++++Unity动画系统基础:https://blog.csdn.net/vrunsoftyanlz/article/details/78886068
++++Unity动画系统进阶:https://blog.csdn.net/vrunsoftyanlz/article/details/78886198
++++Navigation导航系统:https://blog.csdn.net/vrunsoftyanlz/article/details/78886281
++++Unity特效渲染:https://blog.csdn.net/vrunsoftyanlz/article/details/78886403
++++Unity数据存储:https://blog.csdn.net/vrunsoftyanlz/article/details/79251273
++++Unity中Sqlite数据库:https://blog.csdn.net/vrunsoftyanlz/article/details/79254162
++++WWW类和协程:https://blog.csdn.net/vrunsoftyanlz/article/details/79254559
++++Unity网络:https://blog.csdn.net/vrunsoftyanlz/article/details/79254902
++++Unity资源加密:https://blog.csdn.net/VRunSoftYanlz/article/details/87644514
++++PhotonServer简介:https://blog.csdn.net/VRunSoftYanlz/article/details/86652770
++++编写Photon游戏服务器:https://blog.csdn.net/VRunSoftYanlz/article/details/86682935
++++C#事件:https://blog.csdn.net/vrunsoftyanlz/article/details/78631267
++++C#委托:https://blog.csdn.net/vrunsoftyanlz/article/details/78631183
++++C#集合:https://blog.csdn.net/vrunsoftyanlz/article/details/78631175
++++C#泛型:https://blog.csdn.net/vrunsoftyanlz/article/details/78631141
++++C#接口:https://blog.csdn.net/vrunsoftyanlz/article/details/78631122
++++C#静态类:https://blog.csdn.net/vrunsoftyanlz/article/details/78630979
++++C#中System.String类:https://blog.csdn.net/vrunsoftyanlz/article/details/78630945
++++C#数据类型:https://blog.csdn.net/vrunsoftyanlz/article/details/78630913
++++Unity3D默认的快捷键:https://blog.csdn.net/vrunsoftyanlz/article/details/78630838
++++游戏相关缩写:https://blog.csdn.net/vrunsoftyanlz/article/details/78630687
++++UnityAPI.Rigidbody刚体:https://blog.csdn.net/VRunSoftYanlz/article/details/81784053
++++UnityAPI.Material材质:https://blog.csdn.net/VRunSoftYanlz/article/details/81814303
++++UnityAPI.Android安卓:https://blog.csdn.net/VRunSoftYanlz/article/details/81843193
++++UnityAPI.AndroidJNI安卓JNI:https://blog.csdn.net/VRunSoftYanlz/article/details/81879345
++++UnityAPI.Transform变换:https://blog.csdn.net/VRunSoftYanlz/article/details/81916293
++++UnityAPI.WheelCollider轮碰撞器:https://blog.csdn.net/VRunSoftYanlz/article/details/82356217
++++UnityAPI.Resources资源:https://blog.csdn.net/VRunSoftYanlz/article/details/83155518
++++JSON数据结构:https://blog.csdn.net/VRunSoftYanlz/article/details/82026644
++++CocosStudio快速入门:https://blog.csdn.net/VRunSoftYanlz/article/details/82356839
++++Unity企业内训(目录):https://blog.csdn.net/VRunSoftYanlz/article/details/82634668
++++Unity企业内训(第1讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82634733
++++Unity企业内训(第2讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82861180
++++Unity企业内训(第3讲):https://blog.csdn.net/VRunSoftYanlz/article/details/82927699
++++Unity企业内训(第4讲):https://blog.csdn.net/VRunSoftYanlz/article/details/83479776
++++Unity企业内训(第5讲):https://blog.csdn.net/VRunSoftYanlz/article/details/83963811
++++Unity企业内训(第6讲):https://blog.csdn.net/VRunSoftYanlz/article/details/84207696
++++钻哥带您了解产品原型:https://blog.csdn.net/VRunSoftYanlz/article/details/87303828
++++插件
++++计算机组成原理(教材篇):https://blog.csdn.net/VRunSoftYanlz/article/details/82719129
++++5G接入:云计算和雾计算:https://blog.csdn.net/VRunSoftYanlz/article/details/88372718
++++云计算通俗讲义:https://blog.csdn.net/VRunSoftYanlz/article/details/88652803
++++立钻哥哥Unity 学习空间: http://blog.csdn.net/VRunSoftYanlz/
--_--VRunSoft:lovezuanzuan--_--