随笔分类 -  数据结构/算法

摘要:usingSystem; namespaceShellSorter { publicclassShellSorter { publicvoidSort(int[]list) { intinc; for(inc=1;inc<=list.Length/9;inc=3*inc+1); for(;inc>0;inc/=3) { for(inti=inc+1;i<=list.Length;i+=inc) { intt=list[i-1]; intj=i; while((j>inc)&&(list[j-inc-1]>t)) { list[j-1]=list[j-inc-1]; j-=inc 阅读全文
posted @ 2007-06-25 13:35 似水流年-johnhuo 阅读(161) 评论(0) 推荐(0) 编辑
摘要:usingSystem; namespaceInsertionSorter { publicclassInsertionSorter { publicvoidSort(int[]list) { for(inti=1;i<list.Length;i++) { intt=list[i]; intj=i; while((j>0)&&(list[j-1]>t)) { list[j]=list[j-1]; --j; } list[j]=t; } } } publicclassMainClass { publicstaticvoidMain() { int[]iArrary=newint[ 阅读全文
posted @ 2007-06-25 13:33 似水流年-johnhuo 阅读(125) 评论(0) 推荐(0) 编辑
摘要:usingSystem; namespaceBubbleSorter { publicclassBubbleSorter { publicvoidSort(int[]list) { inti,j,temp; booldone=false; j=1; while((j<list.Length)&&(!done)) { done=true; for(i=0;i<list.Length-j;i++) { if(list[i]>list[i+1]) { done=false; temp=list[i]; list[i]=list[i+1]; list[i+1]=temp; } } j+ 阅读全文
posted @ 2007-06-25 13:32 似水流年-johnhuo 阅读(179) 评论(0) 推荐(0) 编辑
摘要:usingSystem; namespaceSelectionSorter { publicclassSelectionSorter { privateintmin; publicvoidSort(int[]list) { for(inti=0;i<list.Length-1;i++) { min=i; for(intj=i+1;j<list.Length;j++) { if(list[j]<list[min]) min=j; } intt=list[min]; list[min]=list[i]; list[i]=t; } } } publicclassMainClass { public. 阅读全文
posted @ 2007-06-25 13:30 似水流年-johnhuo 阅读(143) 评论(0) 推荐(0) 编辑
摘要:// binarySearch.java// demonstrates recursive binary search// to run this program: C>java BinarySearchApp////////////////////////////////////////////////////////////////class ordArray { private long[] a; // ref to array a private int nElems; // number of data items //----------------------------- 阅读全文
posted @ 2007-04-26 16:54 似水流年-johnhuo 阅读(314) 评论(0) 推荐(0) 编辑
摘要:// stack.java// demonstrates stacks// to run this program: C>java StackApp////////////////////////////////////////////////////////////////class StackX { private int maxSize; // size of stack array private long[] stackArray; private int top; // top of stack//--------------------------------------- 阅读全文
posted @ 2007-04-26 16:51 似水流年-johnhuo 阅读(281) 评论(0) 推荐(0) 编辑
摘要:// bubbleSort.java// demonstrates bubble sort// to run this program: C>java BubbleSortApp////////////////////////////////////////////////////////////////class ArrayBub { private long[] a; // ref to array a private int nElems; // number of data items//---------------------------------------------- 阅读全文
posted @ 2007-04-26 16:45 似水流年-johnhuo 阅读(130) 评论(0) 推荐(0) 编辑
摘要:快速排序算法void quicksort (sqlist r, int s, int t){ int i=s, j=t; if (s<t) do { r[0] =r[s]; /*r[0]暂存选出的数据*/ while( j>1 && r[j].key >=r[0].key) j--; if (i<j) { r[i]=r[j]; i++; } 快速排序算法续 while (i<j && r[i].key <=r[0].key) i++; if (i<j) { r[j]=r[i]; j--; } }while (i<j 阅读全文
posted @ 2007-04-26 16:18 似水流年-johnhuo 阅读(124) 评论(0) 推荐(0) 编辑
摘要:简单选择排序算法void selectsort (sqlist r, int n){ int i, j, min; for (i=1;i<=n-1;i++) { min=i; /*用min指出每一趟在无序区范围内的最小元素*/ 简单选择排序算法续 for (j=i+1;j<=n-1;j++) if (r[j].key < r[min].key) min=j; r[0] = r[i]; /* r[0]用于暂时存放元素*/ r[i] = r[min]; r[min] =r[0]; }} 阅读全文
posted @ 2007-04-26 16:16 似水流年-johnhuo 阅读(126) 评论(0) 推荐(0) 编辑
摘要:public void BubbleSort(int[] R) { int i,j,temp; //交换标志 bool exchange; for(i=0; i<R.Length; i++) //最多做R.Length-1趟排序 { exchange=false; //本趟排序开始前,交换标志应为假 for(j=R.Length-2; j>=i; j--) { if(R[j+1]<R[j]) //交换条件 { temp=R[j+1]; R[j+1]=R[j]; R[j]=temp; exchange=true; //发生了交换,故将交换标志置为真 } } if(!exchan 阅读全文
posted @ 2007-04-24 15:40 似水流年-johnhuo 阅读(206) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示