91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

各個排序算法的java實現 包括 插入排序(直接插入和希爾排序) 交換排序(起泡排序和快速排序) 選擇排序(簡單選擇和堆排序) 歸并排序

資源截圖

代碼片段和文件信息

//各種排序測試
import?java.util.Random;
import?javax.swing.*;
import?java.awt.*;
import?java.awt.event.*;

class?SortGui?extends?Jframe?implements?ActionListener
{
JLabel?label1=new?JLabel(“各種排序性能測試“);
????JLabel?label2=new?JLabel(“排序算法“);
JLabel?label3=new?JLabel(“記錄個數“);

????JTextField?text1=new?JTextField();
JTextField?text2=new?JTextField();

String?s[]?={“直接插入排序““希爾排序““起泡排序““快速排序““簡單選擇排序““堆排序“
“歸并排序(非遞歸)““歸并排序(遞歸)“};
JComboBox?combo=new?JComboBox(s);

JButton?button1=new?JButton(“排序“);
JButton?button2=new?JButton(“隨機生成“);

static?JLabel?output=new?JLabel(“提示:1.數據生成:在輸入框輸入你要排序的記錄用空格隔開?按Enter?或者?在記錄個數框輸入記錄個數?按?隨機生成??2.排序:選擇排序方式后按?排序?“);

static?JTextArea?textarea=new?JTextArea();
int[]?num;???????????????//用以存放隨機生成的記錄
int?[]?r1;???????????????//二路歸并排序算法須用到一個與存放待排序記錄等長的數組

long?start=0;
long?over=0;

SortGui()
{
super(“各種排序時間性能測試“);
????????setLayout(null);

????????add(label1);
label1.setBounds(1501012015);
add(text1);
text1.setBounds(53042530);

????????add(label2);
label2.setBounds(10805515);
add(combo);
combo.setBounds(657810025);

add(button1);
button1.setBounds(290756025);

add(label3);
label3.setBounds(101305515);
add(text2);
text2.setBounds(6512510025);

add(button2);
button2.setBounds(2901259025);


add(output);
output.setForeground(Color.blue);
output.setBounds(516043545);

add(textarea);
textarea.setBounds(5210425200);
????textarea.setLineWrap(true);??//設置文本區自動換行
????Font?f=new?Font(“宋體“Font.BOLD25);
????textarea.setFont(f);
????????textarea.setForeground(Color.magenta);

text1.addActionListener(this);
text2.addActionListener(this);
button1.addActionListener(this);
button2.addActionListener(this);


setVisible(true);
setSize(450450);
}
? public?void?actionPerformed(ActionEvent?e)
????{
if(e.getSource()==text1)
{
String?temp1=text1.getText();
String[]?temp2=temp1.split(“\\s“);
num=new?int[temp2.length+1];
r1=new?int[temp2.length+1];
for(int?i=1;i num[i]=Integer.parseInt(temp2[i-1]);??//注意是temp2[i-1]
Print();
}
if(e.getSource()==button1)
{
??try{
switch(combo.getSelectedIndex())
{
case?0: ???//直接插入排序
{
start?=?System.nanoTime();
InsertSort(numnum.length-1);???//由于r[0]是空出來的?所以數組元素個數是length-1
over?=?System.nanoTime();
output.setText(null);
output.setText(“排序的時間是:?“?+?(over?-?start)/1000+?“微秒“);
Print();
}
break;

case?1:????????????????????????????//希爾排序
{
start?=?System.nanoTime();
ShellSort(numnum.length-1);
over?=?System.nanoTime();
output.setText(null);
output.setText(“排序的時間是:?“?+?(over?-?start)/1000?+?“微秒“);
Print();
}
break;

case?2:????????????????????????????//起泡排序
{
start?=?System.nanoTime();
?? BubbleSort(numnum.lengt

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件??????11707??2011-06-13?21:57??SortGui.java

-----------?---------??----------?-----??----

????????????????11707????????????????????1


評論

共有 條評論