Java Data Structure
共 2 篇文章
Java数据结构和算法--排序
差别: 冒泡要不停的交换,选择是碰到最小的,和最前面的索引位置的进行交换。 排序的方法有:插入排序(直接插入排序、希尔排序),交换排序(冒泡排序、快速排序),选择排序(直接选择排序、堆排序),归并排序,分配排序(箱排序、基数排序) 1.冒泡排序 package ChapterOne; public class Bubble { public static void main(String[] args) { Bubble b = new Bubble(); for(int i = 0;i < arr.length;i++){ System.out.print(arr[i]+" "); } S…
2008-11-15 05:24 · Java Data Structure
二叉树算法,实现添加数据形成二叉树功能,并以先序的方式打印出来
import java.io.*; import java.util.Stack; public class myTest { private myTree tree; /** *二叉树的插入,参数为(关键字,数据) * **/ public void insert(int key, int data) { if(tree == null) { tree = new myTree(); tree.key = key; tree.data = data; } else { myTree newTree = new myTree(); newTree.key = key; newTree.dat…
2008-11-15 03:40 · Java Data Structure