algorithm ch2 insertsort
刚开始看到insertsort,思路就是使用新来的元素与前述已经排好序的元素比较。然后进行插入或者跳到下一次比较。
实现的代码如下:
void InsertSort(int *pArray, int iSortNum)
{
int *pTemp = pArray;
int iLoop = ;
int jLoop = ; for(; jLoop != iSortNum ; ++jLoop)
{
int x = pTemp[jLoop];
iLoop = jLoop - ;
while(pArray[iLoop] >x && iLoop>=)
{
pArray[iLoop+] = pArray[iLoop];
--iLoop;
}
pArray[iLoop+] = x; }
}
这种排序跟冒泡法时间复杂度都是o(n^2),属于就地排序,空间复杂度o(1)。
algorithm ch2 insertsort的更多相关文章
- algorithm ch2 Merge_sort
这是用分治法来对序列进行排序,将较长的一个序列分解为n个比较短的序列,然后分别处理这n个较小的段序列,最后合并.使用递归的来实现. 具体实现的代码如下: void MergeSort(int *A, ...
- Java算法-堆排序
package org.rut.util.algorithm.support; import org.rut.util.algorithm.SortUtil; public class HeapSor ...
- Java算法-希尔排序
希尔排序的诞生是由于插入排序在处理大规模数组的时候会遇到需要移动太多元素的问题.希尔排序的思想是将一个大的数组“分而治之”,划分为若干个小的数组,以 gap 来划分,比如数组 [1, 2, 3, 4, ...
- Java中各种排序算法
package org.rut.util.algorithm.support; import org.rut.util.algorithm.SortUtil; /** * @author treero ...
- 用Java实现几种常见的排序算法
用Java语言实现的各种排序,包括插入排序.冒泡排序.选择排序.Shell排序.快速排序.归并排序.堆排序.SortUtil等. 插入排序: package org.rut.util.algorith ...
- 常见排序算法题(java版)
常见排序算法题(java版) //插入排序: package org.rut.util.algorithm.support; import org.rut.util.algorithm.Sor ...
- The algorithm learning of sort which include Bubblesort,Insertsort,Quicksort and Mergesort.
Notice : these algorithms achieved by Java. So,let's going to it. firstly, what is Bubblesort? why w ...
- algorithm -- 插入排序
插入排序是<算法导论>中第一个介绍的算法,详细分析了插入排序的原理,执行过程,证明了算法的正确性.同时也引出了算法分析和算法分析常用的方法. 此文对原文作个转述,检验学到的知识. 文中使用 ...
- Algorithm | Sort
Bubble sort Bubble sort, sometimes incorrectly referred to as sinking sort, is a simple sorting algo ...
随机推荐
- win10子系统Ubuntu18.04下安装图形界面
前提:windows 10 已经安装WSL(windows subsystem for linux),并能正确运行Bash. 要想使用Linux的图形用户界面通常有两种方法,一种是使用X-Window ...
- Python 3基础教程20-Python中导入模块和包
本文介绍Python中导入模块和包 #目录: # 导入模块和包--- # | # 上级包.上级模块.导入模块和包的init模块----- # | # 同级包.同级模块.上级包的init模块.test模 ...
- [leetcode-655-Print Binary Tree]
Print a binary tree in an m*n 2D string array following these rules: The row number m should be equa ...
- linux学习(二)——汤哥的推荐书籍
成为一名精通 Linux程序设计的高级程序员一直是不少朋友孜孜以求的目标. 根据中华英才网统计数据,北京地区 Linux 程序员月薪平均为 Windows程序员的 1.8 倍.Java 程序员的 2. ...
- Week2 Teamework from Z.XML 软件分析与用户需求调查(四)Bing桌面及助手的现状与发展
一.Bing搜索的相关背景 第一,必应搜索前几年的发展重点在于欧美市场,并且取得了一定的成效:根据 Hitwise 的统计数据,Bing 在 2011年3 月份市场占有率突破了 30% 大关,达到 3 ...
- mysql 数据库新增用户
1.user表中host为%含义: Host列指定了允许用户登录所使用的IP,比如user=root Host=192.168.1.1.这里的意思就是说root用户只能通过192.168.1.1的客户 ...
- Friends and Enemies(思维)
Friends and Enemies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- 【UML】类图介绍
1.类图是面向对象系统建模中最常用和最重要的图,是定义其它图的基础.类图主要是用来显示系统中的类.接口以及它们之间的静态结构和关系的一种静态模型. 2.类的关系有泛化(Generalization). ...
- TCP/IP Note1
TCP/IP(Transmission Control Protocol / Internet Protocol)是用于Internet的通信协议. 计算机通信协议:是指对那些计算机必须遵守以便彼此通 ...
- How to Create a Perl Based Custom Monitor on NetScaler
How to Create a Perl Based Custom Monitor on NetScaler https://support.citrix.com/article/CTX227727 ...