数据结构之排序算法
发布时间:2020-12-13 21:15:47 所属栏目:PHP教程 来源:网络整理
导读:#include#include#include#include#includeusing namespace std;void print(int a[],int n,int i) {cout i ":"; for (int j = 0; j8; j++) { cout a[j] " "; } cout endl; } void swap(int a,int b) { int temp; temp = a; a = b; b = temp; } /*插入排序:
#include#include#include#include#includeusing namespace std;
void print(int a[],int n,int i) {
cout << i << ":"; for (int j = 0; j<8; j++) { cout << a[j] << " "; } cout << endl; } void swap(int a,int b) { int temp; temp = a; a = b; b = temp; } /*插入排序: 将第1待排序序列第1个元素看作1个有序序列,把第2个元素到最后1个元素当做是未排序序列。 从头到尾顺次扫描未排序序列,将扫描到的每一个元素插入有序序列的适当位置。 如果待插入的元素与有序序列中的某个元素相等,则将待插入元素插入到相等元素的后面。 * 时间复杂度也为O(n^2),比冒泡法和选择排序的性能要更好1些 */ void InsertSort(int a[],int n) { for (int i = 1; i
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |