摘要: // 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 阅读(313) 评论(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 阅读(279) 评论(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 阅读(128) 评论(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 阅读(123) 评论(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 阅读(125) 评论(0) 推荐(0) 编辑