deepsort算法 排序算法:有100萬數(shù)據(jù),用卙用內(nèi)存最小和排序最忋void sort(int* array, int n) 其中你n的值為100萬左右?
排序算法:有100萬數(shù)據(jù),用卙用內(nèi)存最小和排序最忋void sort(int* array, int n) 其中你n的值為100萬左右?int type的最大值是32767,因此可以存儲(chǔ)在32767的
排序算法:有100萬數(shù)據(jù),用卙用內(nèi)存最小和排序最忋void sort(int* array, int n) 其中你n的值為100萬左右?
int type的最大值是32767,因此可以存儲(chǔ)在32767的int數(shù)組中。
void sort(int*array,int n){
int*array=new int[32767
]Zeroumemory(array,sizeof(int)*32767)
for(long i=0 i< n i){
int dataui=read(i)//獲取第i個(gè)數(shù)
array[datai]那么數(shù)組的下標(biāo)就是數(shù)據(jù),元組的值就是數(shù)據(jù)數(shù),0表示沒有這樣的數(shù)據(jù)。
遍歷此數(shù)組后,可以得到排序序列,
memory 32767*sizeof(int),time n
1 public class selectsort{
2 public static int[]selectsort(int[]a){
3 int n=a.length
4 for(int i=0 i< n-1 i){
5 int min=i
6 for(int j=i 1 j< n j){
7 if(a[min]> a[J])min=J
8}
9//exchange
10 int temp=a[i
]11 a[i]=a[min
]12 a[min]=temp
13}
14返回a
15}
16}
屬性:1。時(shí)間復(fù)雜度:O(N2)2。空間復(fù)雜度:O(1)3。不穩(wěn)定排序4。原位分選