标签:style blog color java os io for ar art
No.1
QuickSort快排
void QuickSort(int[] l,int left,int right) { if(left<right) int pivotpos=partion(l,left,right); QuickSort(l,lefft,pivotpos-1); QuickSort(l,pivotpos+1,rigth); } int partition(int[] l,int low,int high){ int pivotpos=low; int pivot=l[low]; for(int i=low+1;i<=high;i++) if(l[i]<pivot){ pivot++; if(pivotpos!=i)Swap(l[i],l[pivotpos]); } l[low]=l[pivotpos];l[pivotpos]=pivot; return pivotpos; }
No2:
BubbleSort(冒泡排序)
BubbleSort(int v[],int n){ for(int int=1;i<n;i++) for(int j=n-1;j>=i;j--) if(v[j-1]>v[j]){ int temp=v[j-1]; v[j-1]=v[j]; v[j]=temp; } }
No3:
MergeSort(归并排序)
void MergeSort(int[] l,int len){ int l2[]=new int[len]; recMergeSort(l,l2,0,len-1); } void recMergeSort(int[] l,int[] l2,int left,int right){ int mid=(left+right)/2; recMergeSort(l,l2,left,mid); recMergeSort(l,l2,mid+1,right); merge(l,l2,left,mid,right); } void merge(int[] l,int[] l2,int left,int mid,int right){ for(int k=left;k<=right;k++){ l2[k]=l[k]; int s1=left,s2=mid+1,t=left; while(s1<=mid&&s2<=right) if(l[s2]<=l[s1])l[t++]=l2[s1++]; else l[t++]=l2[s2++]; while(s1<=mid)l[t++]=l2[s1++]; while(s2<=right)l[t++]=l2[s2++]; } }
No4:
BinarySearch(二分搜索)
int BinarySearch(int[] l,int x,int low,int high){ int mid=0; if(low<=high){ mid=(low+high)/2; if(x>l[mid])mid=BinarySeaech(l,c,mid+1,high); else if(x<l[mid])mid=BinarySeaech(l,c,low,mid+1); } return mid; }
No5:
HeapSort(堆排序)
再更。。。。。
标签:style blog color java os io for ar art
原文地址:http://www.cnblogs.com/tryao/p/3935036.html