欢迎来到天天文库
浏览记录
ID:36223662
大小:103.00 KB
页数:10页
时间:2019-05-07
《java数据结构及算法new》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、packagepaixu;//冒泡排序classArrayBub{privatelong[]a;privateintnElems;publicArrayBub(intmax){a=newlong[max];nElems=0;}publicvoidinsert(longvalue){a[nElems]=value;nElems++;}publicvoiddisplay(){for(intj=0;j2、eSort(){intout,in;for(out=nElems-1;out>1;out--)for(in=0;ina[in+1])swap(in,in+1);}privatevoidswap(intone,inttwo){longtemp=a[one];a[one]=a[two];a[two]=temp;}}publicclassBubbleSortApp{publicstaticvoidmain(String[]args){intmaxSize=100;ArrayBubarr;arr=newArrayBub(3、maxSize);arr.insert(77);……arr.display();arr.bubbleSort();arr.display();}}packagepaixu;//选择排序classArraySel{privatelong[]a;privateintnElems;publicArraySel(intmax){a=newlong[max];nElems=0;}publicvoidinsert(longvalue){a[nElems]=value;nElems++;}publicvoiddisplay(){for(intj=0;j4、s;j++)System.out.println(a[j]+"");System.out.println("");}publicvoidselectionSort(){intout,in,min;for(out=0;out5、publicclassSelectSortApp{publicstaticvoidmain(String[]args){intmaxSize=100;ArraySelarr;arr=newArraySel(maxSize);arr.insert(77);…………arr.display();arr.selectionSort();arr.display();}}packagepaixu;//插入排序classArrayIns{privatelong[]a;privateintnElems;publicArrayIns(intmax){a=newlong6、[max];nElems=0;}publicvoidinsert(longvalue){a[nElems]=value;nElems++;}publicvoiddisplay(){for(intj=0;j0&&a[in-1]>=temp7、){a[in]=a[in-1];--in;}a[in]=temp;}}}publicclassInsertSortApp{publicstaticvoidmain(String[]args){intmaxSize=100;ArrayInsarr;arr=newArrayIns(maxSize);arr.insert(77);………arr.display();arr.insertionSort();arr.display();}}packagepaixu;//栈classStackX{privateintmaxSize;privatelong[]sta8、ckArray;privateinttop;publicStackX(ints){maxSize=s;sta
2、eSort(){intout,in;for(out=nElems-1;out>1;out--)for(in=0;ina[in+1])swap(in,in+1);}privatevoidswap(intone,inttwo){longtemp=a[one];a[one]=a[two];a[two]=temp;}}publicclassBubbleSortApp{publicstaticvoidmain(String[]args){intmaxSize=100;ArrayBubarr;arr=newArrayBub(
3、maxSize);arr.insert(77);……arr.display();arr.bubbleSort();arr.display();}}packagepaixu;//选择排序classArraySel{privatelong[]a;privateintnElems;publicArraySel(intmax){a=newlong[max];nElems=0;}publicvoidinsert(longvalue){a[nElems]=value;nElems++;}publicvoiddisplay(){for(intj=0;j4、s;j++)System.out.println(a[j]+"");System.out.println("");}publicvoidselectionSort(){intout,in,min;for(out=0;out5、publicclassSelectSortApp{publicstaticvoidmain(String[]args){intmaxSize=100;ArraySelarr;arr=newArraySel(maxSize);arr.insert(77);…………arr.display();arr.selectionSort();arr.display();}}packagepaixu;//插入排序classArrayIns{privatelong[]a;privateintnElems;publicArrayIns(intmax){a=newlong6、[max];nElems=0;}publicvoidinsert(longvalue){a[nElems]=value;nElems++;}publicvoiddisplay(){for(intj=0;j0&&a[in-1]>=temp7、){a[in]=a[in-1];--in;}a[in]=temp;}}}publicclassInsertSortApp{publicstaticvoidmain(String[]args){intmaxSize=100;ArrayInsarr;arr=newArrayIns(maxSize);arr.insert(77);………arr.display();arr.insertionSort();arr.display();}}packagepaixu;//栈classStackX{privateintmaxSize;privatelong[]sta8、ckArray;privateinttop;publicStackX(ints){maxSize=s;sta
4、s;j++)System.out.println(a[j]+"");System.out.println("");}publicvoidselectionSort(){intout,in,min;for(out=0;out5、publicclassSelectSortApp{publicstaticvoidmain(String[]args){intmaxSize=100;ArraySelarr;arr=newArraySel(maxSize);arr.insert(77);…………arr.display();arr.selectionSort();arr.display();}}packagepaixu;//插入排序classArrayIns{privatelong[]a;privateintnElems;publicArrayIns(intmax){a=newlong6、[max];nElems=0;}publicvoidinsert(longvalue){a[nElems]=value;nElems++;}publicvoiddisplay(){for(intj=0;j0&&a[in-1]>=temp7、){a[in]=a[in-1];--in;}a[in]=temp;}}}publicclassInsertSortApp{publicstaticvoidmain(String[]args){intmaxSize=100;ArrayInsarr;arr=newArrayIns(maxSize);arr.insert(77);………arr.display();arr.insertionSort();arr.display();}}packagepaixu;//栈classStackX{privateintmaxSize;privatelong[]sta8、ckArray;privateinttop;publicStackX(ints){maxSize=s;sta
5、publicclassSelectSortApp{publicstaticvoidmain(String[]args){intmaxSize=100;ArraySelarr;arr=newArraySel(maxSize);arr.insert(77);…………arr.display();arr.selectionSort();arr.display();}}packagepaixu;//插入排序classArrayIns{privatelong[]a;privateintnElems;publicArrayIns(intmax){a=newlong
6、[max];nElems=0;}publicvoidinsert(longvalue){a[nElems]=value;nElems++;}publicvoiddisplay(){for(intj=0;j0&&a[in-1]>=temp
7、){a[in]=a[in-1];--in;}a[in]=temp;}}}publicclassInsertSortApp{publicstaticvoidmain(String[]args){intmaxSize=100;ArrayInsarr;arr=newArrayIns(maxSize);arr.insert(77);………arr.display();arr.insertionSort();arr.display();}}packagepaixu;//栈classStackX{privateintmaxSize;privatelong[]sta
8、ckArray;privateinttop;publicStackX(ints){maxSize=s;sta
此文档下载收益归作者所有