資源描述:
《中南大學(xué)算法實驗報告》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、中南大學(xué)《算法分析與設(shè)計》實驗報告姓名:專業(yè)班級:軟件工程1005學(xué)號:指導(dǎo)教師:完成日期:2011.1245實驗1分治算法實驗1、實驗?zāi)康?1)了解分治策略算法思想(2)掌握快速排序、歸并排序算法(3)了解其他分治問題典型算法2、實驗內(nèi)容(1)編寫一個簡單的程序,實現(xiàn)歸并排序。(2)編寫一段程序,實現(xiàn)快速排序。該實驗我采用了java語言,在實驗過程中,我發(fā)現(xiàn)java不能像c++一樣傳遞參數(shù)的引用,因而只能采用數(shù)組。采用歸并排序:4545采用快速排序:4545代碼:packageSorts;importjava.awt.*;import
2、java.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;importjava.util.Random;45publicclassSortextendsFrame{privateintNum[]=newint[10];privatePanelReadylist;privatePanelFunction;privatePanelResul
3、t;privatePanelPnum;privatePanelRenum;privateButtonnum1;privateButtonnum2;privateButtonnum3;privateButtonnum4;privateButtonnum5;privateButtonnum6;privateButtonnum7;privateButtonnum8;privateButtonnum9;privateButtonnum10;privateButtonrandomdata;privateButtonreadylist;privat
4、eButtonmergesort;privateButtonquicksort;privateButtonresetdata;privateButtonexit;privateButtonsortresult;privateTextFieldpnum1;privateTextFieldpnum2;45privateTextFieldpnum3;privateTextFieldpnum4;privateTextFieldpnum5;privateTextFieldpnum6;privateTextFieldpnum7;privateTex
5、tFieldpnum8;privateTextFieldpnum9;privateTextFieldpnum10;privateTextFieldrenum1;privateTextFieldrenum2;privateTextFieldrenum3;privateTextFieldrenum4;privateTextFieldrenum5;privateTextFieldrenum6;privateTextFieldrenum7;privateTextFieldrenum8;privateTextFieldrenum9;private
6、TextFieldrenum10;publicSort(Stringtitle){super(title);setSize(400,600);setLocation(100,100);setReadylist();setFunction();setResult();setLayout(newGridLayout(1,3));add(Readylist);add(Function);add(Result);45addWindowListener(newWindowAdapter(){publicvoidwindowClosing(Wind
7、owEvente){System.exit(0);}});}publicvoidsetReadylist(){Readylist=newPanel();readylist=newButton("待排序數(shù)組");num1=newButton("NUM1");num2=newButton("NUM2");num3=newButton("NUM3");num4=newButton("NUM4");num5=newButton("NUM5");num6=newButton("NUM6");num7=newButton("NUM7");num8=
8、newButton("NUM8");num9=newButton("NUM9");num10=newButton("NUM10");pnum1=newTextField();pnum2=newTextFie