資源簡介
分別采用二叉鏈表和順序表作存儲結構,實現對二叉排序樹與平衡二叉樹的操作。
重慶理工大學,軟件工程系,課程設計。
重慶理工大學,軟件工程系,課程設計。
代碼片段和文件信息
/**
?*?@author?cnzx219
?*?@email??cnzx219@qq.com
?*?@date???2011-12-19
?*?All?rights?reserved.?
?*?Copyright?2011?cnzx219
**/
package?course.design6;
import?java.awt.*;
import?javax.swing.*;
import?java.awt.event.ActionListener;
import?java.awt.event.ActionEvent;
import?java.util.linkedList;
import?java.util.Queue;
import?course.design6.algorithm.*;
public?class?TestBSTWindow?extends?Jframe?{
/**
?*?
?*/
private?static?final?long?serialVersionUID?=?-1995115129244377767L;
public?TestBSTWindow?mainWindow;
public?TreeViewer?pnlView;
/**
?*?Launch?the?application.
?*/
public?static?void?main(String[]?args)?{
EventQueue.invokeLater(new?Runnable()?{
public?void?run()?{
try?{
TestBSTWindow?frame?=?new?TestBSTWindow();
frame.setVisible(true);
}?catch?(Exception?e)?{
e.printStackTrace();
}
}
});
}
/**
?*?Create?the?frame.
?*/
public?TestBSTWindow()?{
mainWindow?=?this;
setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
setBounds(10?10?1030?689);
getContentPane().setLayout(new?BorderLayout(0?0));
JPanel?pnlCommandBar?=?new?JPanel();
FlowLayout?fl_pnlCommandBar?=?(FlowLayout)?pnlCommandBar.getLayout();
fl_pnlCommandBar.setAlignment(FlowLayout.LEFT);
getContentPane().add(pnlCommandBar?BorderLayout.NORTH);
JButton?btnAddNode?=?new?JButton(“\u6DFB\u52A0\u8282\u70B9“);
btnAddNode.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?e)?{
String?s?=?JOptionPane.showInputDialog(mainWindow?“請輸入要插入節點的數據:“);
if?(s?!=?null?&&?s.length()?>?0)?{
if?(pnlView.t.find(s)?==?null)?{
pnlView.t.insert(s);
pnlView.refreshTree(pnlView.t);
}
else?{
JOptionPane.showMessageDialog(mainWindow?“節點“?+?s?+?“已存在!“);
}
}
}
});
pnlCommandBar.add(btnAddNode);
JButton?btnRemoveNode=?new?JButton(“\u5220\u9664\u8282\u70B9“);
btnRemoveNode.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?e)?{
String?s?=?JOptionPane.showInputDialog(mainWindow?“請輸入要插入節點的數據:“);
if?(s?!=?null?&&?s.length()?>?0)?{
if?(pnlView.t.find(s)?==?null)?{
JOptionPane.showMessageDialog(mainWindow?“無“?+?s?+?“。“);
}
else?{
if?(s.compareTo(pnlView.root.getData())?==?0?&&?BiTree.count(pnlView.root)?==?1)?{
pnlView.root?=?null;
}
pnlView.t.remove(s);
pnlView.makeView();
}
}
}
});
pnlCommandBar.add(btnRemoveNode);
JButton?btnNewButton_1?=?new?JButton(“\u5220\u9664\u9009\u62E9\u8282\u70B9“);
btnNewButton_1.addActionListener(new?ActionListener()?{
public?void?actionPerformed(ActionEvent?e)?{
if?(pnlView.getSelectedNode()?!=?null)?{
if?(pnlView.getSelectedNode().compareTo(pnlView.root.getData())?==?0?&&?BiTree.count(pnlView.root)?==?1)?{
pnlView.root?=?null;
}
pnlView.t.remove(pnlView.getSelectedNod
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????5082??2007-12-23?11:58??TestBSTWindow.java
?????文件???????4888??2012-01-09?11:48??TreeViewer.java
?????文件???????8726??2007-12-23?11:57??algorithm\AVLBiSearchTree.java
?????文件????????544??2011-12-24?15:17??algorithm\BiSearchTree.java
?????文件???????4769??2011-12-24?15:17??algorithm\BiSearchTreeLnk.java
?????文件???????6090??2011-12-24?15:17??algorithm\BiSearchTreeSeq.java
?????文件???????1995??2011-12-24?15:17??algorithm\BiTree.java
?????文件????????942??2007-12-23?11:57??algorithm\BiTreeNode.java
?????文件????????242??2011-12-24?15:17??algorithm\VisitListener.java
?????文件???????2456??2011-12-24?15:17??console\TestBiSearchTree.java
?????文件???????1788??2011-12-24?15:17??console\TestBiSearchTreeSeq.java
?????目錄??????????0??2011-12-24?15:17??algorithm
?????目錄??????????0??2011-12-22?22:01??console
-----------?---------??----------?-----??----
????????????????37522????????????????????13
評論
共有 條評論