摘要:归并排序,其的基本思路就是将数组分成二组A,B,如果这二组组内的数据都是有序的,那么就可以很方便的将这二组数据进行排序。如何让这二组组内数据有序了?可以将A,B组各自再分成二组。依次类推,当分出来的小组只有一个数据时,可以认为这个小组组内已经达到了有序,然后再合并相邻的二个小组就可以了。这样通过先递...
阅读全文
摘要:1.堆堆实际上是一棵完全二叉树,其任何一非叶节点满足性质: Key[i]<=key[2i+1]&&Key[i]<=key[2i+2]或者Key[i]>=Key[2i+1]&&key>=key[2i+2] 即任何一非叶节点的关键字不大于或者不小于其左右孩子节点的关键字。 堆分为大顶堆和小顶堆,满足Key[i]>=Key[2i+1]&&key>=key[2i+2]称为大顶堆,满足 Key[i]<=key[2i+1]&&Key[i]<=key[2i+2]称为小顶堆。由上述性质可知大顶堆的堆
阅读全文
摘要:1 #include <stdio.h> 3 void shell_order(int *a,int length) 4 { 5 int increment,i,j,tem; 6 for(increment = length/2; increment > 0; increment /=2) 7 { 8 for(i = increment; i < length; i++) 9 {10 tem = a[i];11 for(j = i; j >= increment; j -= increme...
阅读全文
摘要:1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 using namespace std; 5 6 int main() 7 { 8 int i,j,tem; 9 int length;10 int a[]={2,43,24,19,25,39,11,6,5};11 // length = a.length();12 length = sizeof(a)/sizeof(int);13 cout<<length<<endl;14 printf("
阅读全文
摘要:1 #include <stdio.h> 2 3 int partition(int *a,int low ,int high) 4 { 5 int privotpos; 6 int tem = a[low]; 7 privotpos = a[low]; 8 while(low<high) 9 {10 while(low<high && a[high]>=privotpos)high--;11 a[low] = a[high];12 while(low<high && a[low]<=privotpos...
阅读全文
摘要:#include <stdio.h>int main(){ int i,j,index,k; int tem,length; int a[10]={2,24,3,19,45,12,1,66,34,7};// length = a.length(); length = 10; printf("Before ordered:\n"); for(i = 0; i < length; i++) printf("%d ",*(a+i)); printf("\n\n"); for(i = 0; i < length; i+
阅读全文
摘要:1 #include <stdio.h> 2 int main() 3 { 4 int i,j,k; 5 int tem,length; 6 int a[10]={2,24,3,19,45,12,1,66,34,7}; 7 // length = a.length(); 8 length = 10; 9 printf("Before ordered:\n");10 for(i = 0; i < length; i++)11 printf("%d ",*(a+i));12 printf("\n\n");13 for(.
阅读全文