资源简介
各个排序算法的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
相关资源
- java图状数据结构转换为树状数据结构
- java算法大全含源码包
- 山东大学数据结构课程设计
- [数据结构Java版第4版][叶核亚][习题解
- 全世界最经典的数据结构教材,Horo
- 数据结构与算法分析Java语言描述-英文
- 数据结构与算法:C#语言描述(中,英
- 数据结构—Java语言描述朱战立版课件
- 数据结构与算法分析_java语言描述_M
- 数据结构课程设计 哈弗曼编码译码器
- 数据结构与算法分析JAVA英文第三版
- 数据结构与算法分析(Java版).pdf
- 图解数据结构使用Java.zip
- 数据结构与算法(java语言)邓俊辉
- 数据结构与算法Java描述 习题答案
- 免费高清 java数据结构和算法第二版编
- Java Design Demo -简单的队列
- 数据结构与算法分析Java描述习题答案
- 数据结构与算法java中文版
- 东北大学数据结构与算法课程设计实
- 2018-2019学年东北大学数据结构实验报
- 武汉大学 数据结构课件
- 算法与数据结构之LeetCode题目详解PD
- 学生成绩管理系统网站数据结构课程
- 数据结构java版 刘小晶
- 数据结构与算法Java 描述 - 邓俊辉 -
- 数据结构与算法分析——java语言描述
- JAVA语言程序设计与数据结构答案
- 数据结构java版练习试卷及答案
- Data Structure and Algorithm Analysis in Java
评论
共有 条评论