sorting - insert sort
来源:互联网 发布:matlab遗传算法cae 编辑:程序博客网 时间:2024/05/20 16:12
#include "stdio.h"#include "string.h"#define MAX_LIST 50typedef struct _SqList { int data[MAX_LIST]; int length;}SqList;void swap( SqList* L, unsigned index1, unsigned index2 ){ if( index1 >= L->length || index2 >= L->length ) return; if( index1 == index2 ) return; L->data[index1] = L->data[index1] ^ L->data[index2]; L->data[index2] = L->data[index1] ^ L->data[index2]; L->data[index1] = L->data[index1] ^ L->data[index2];}//insert sort continuously inserts one element into a sorted array//shifts elements sequentially to the right one by one until a proper//position is secured for the new elementvoid InsertSort(SqList* L){ int i, j, temp; for( i = 1; i < L->length; i++ ) { temp = L->data[i]; for( j = i - 1; j >-1 && temp < L->data[j]; j-- ) { L->data[j+1] = L->data[j]; } L->data[j+1] = temp; }}int main(){ SqList d; int intarr[] = {1,10,23,48,65,31,-21,9,88,100}; memcpy( d.data, intarr, sizeof(intarr)); d.length = sizeof(intarr)/sizeof(int); int index = 0; printf("Original array:\n"); for( ; index < d.length; index++ ) printf(" %d", d.data[index] ); printf("\nSelect sort...\n"); InsertSort( &d ); for( index = 0; index < d.length; index++ ) printf(" %d", d.data[index] ); printf("\n"); return 0;}
0 0
- sorting - insert sort
- insert-sorting
- insert sorting
- insert sort
- Insert sort
- INSERT-SORT
- Insert Sort
- Insert Sort
- insert sort
- insert sort
- insert sort
- insert sort
- insert sort
- Insert Sort
- Insert sort
- poj 2388 insert sorting
- Sorting Algorithms ------[Insertion Sort]
- 【Leetcode】Sort List (Sorting)
- Java中equals方法解析
- Belated enlightenment on Quaternion
- 自然语言处理(NLP)网上资源整理
- Qt数据库总结
- Spring3工具类
- sorting - insert sort
- 漫谈C语言及如何学习C语言
- 自然语言处理(nlp)的主要范畴
- Sicily 13916. Smallest Box
- 进口印度神油阿育吠陀情趣用品男红油防早泄保健延时增大按摩精油
- Android开发基础之Worker线程向Main线程发送消息
- Sicily 7907. Flipper
- Sicily 1401. Children of the Candy Corn
- html5视频和表单