资源简介
直接演示:求深度优先遍历、广度优先遍历、最短路径、最小生成树
代码片段和文件信息
package hartech.ds;
/**
*
* title: Queue
*
* Description:
*
* Website: www.hartech.cn
* Page: http://www.hartech.cn/blog/blogview.asp?logID=88
*
* Date: 2006-08-29
*/
interface Interface_Queue {
// only copy references
public Queue clone();
// out queue from head
// when is empty return null
public object deQueue();
// enter queue from tail
public void enQueue(object o);
// get the head elem in the queue
// if empty return null
public object getHead();
// get the tail elem in the queue
public object getTail();
public int getLength();
public boolean isEmpty();
// print all the elem from head to tail
// return the print string
public String printAll();
// reverse all the elems from head to tail
public void reverse();
public void clean();
}
public class Queue
implements Cloneable Interface_Queue {
class Node
implements Cloneable {
object elem;
Node next;
Node(object elem Node next) {
this.elem = elem;
this.next = next;
}
// only copy references
public Node clone() {
try {
Node n = (Node)super.clone();
n.elem = this.elem;
if (this.next != null) {
n.next = (Node)this.next.clone();
}
else {
n.next = null;
}
return n;
}
catch (CloneNotSupportedException ex) {
System.err.println(“Ooop: Clone Not Supported Exception“);
ex.printStackTrace();
}
return null;
}
}
// have head node
// when the queue is emptythe head and tail point to the same head node
// enQueue from tail
// deQueue from head
private Node head = new Node(null null);
private Node tail = head;
private int length = 0;
// only copy references
public Queue clone() {
try {
Queue n = (Queue)super.clone();
n.head = this.head.clone();
Node p = n.head;
while (p.next != null) {
p = p.next;
}
n.tail = p;
return n;
}
catch (CloneNotSupportedException ex) {
System.out.println(“Ooop: Clone Not Supported Exception“);
ex.printStackTrace();
}
return null;
}
// enter queue from tail
public void enQueue(object o) {
tail.next = new Node(o null);
tail = tail.next;
length++;
}
// out queue from head
// when is empty return null
public object deQueue() {
if (isEmpty()) {
return null;
}
Node p = head.next;
head.next = p.next;
if (tail == p) {
tail = head;
}
length--;
return p.elem;
}
// reverse all the elems from head to tail
public void reverse() {
if (length <= 1) {
return;
}
tail = head.next;
Node q = head.next p = q.next r = p.next;
q.next = null;
// when only two nodes
if (r == nu
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
I.A.... 5280 2006-09-23 23:57 scr\hartech\ds\Queue.java
I..D... 0 2006-09-23 23:51 scr\hartech\ds
I..D... 0 2006-09-23 23:50 scr\hartech\kids\grapher
I..D... 0 2006-09-23 23:50 scr\hartech\kids
I.A.... 6191 2006-09-23 23:56 scr\hartech\ui\J.java
I..D... 0 2006-08-29 11:06 scr\hartech\ui
I..D... 0 2006-09-08 22:39 scr\hartech
I..D... 0 2006-09-23 23:55 scr
文件 77349 2007-06-22 22:57 Grapher.jar
I.A.... 13627 2007-06-22 22:54 scr\hartech\kids\grapher\UI.java
I.A.... 1398 2006-04-25 17:03 scr\hartech\kids\grapher\images\smiles\0.gif
I.A.... 1760 2006-04-25 17:03 scr\hartech\kids\grapher\images\smiles\1.gif
I.A.... 509 2004-12-19 00:19 scr\hartech\kids\grapher\images\smiles\10.gif
I.A.... 708 2006-08-25 12:40 scr\hartech\kids\grapher\images\smiles\11.gif
I.A.... 467 2006-08-25 12:41 scr\hartech\kids\grapher\images\smiles\12.gif
I.A.... 696 2006-08-25 12:41 scr\hartech\kids\grapher\images\smiles\13.gif
I.A.... 1436 2006-08-25 12:41 scr\hartech\kids\grapher\images\smiles\14.gif
I.A.... 462 2006-08-25 12:41 scr\hartech\kids\grapher\images\smiles\15.gif
I.A.... 2256 2006-04-25 17:03 scr\hartech\kids\grapher\images\smiles\16.gif
I.A.... 697 2006-08-25 12:41 scr\hartech\kids\grapher\images\smiles\17.gif
I.A.... 1555 2006-04-25 17:03 scr\hartech\kids\grapher\images\smiles\18.gif
I.A.... 1944 2006-04-25 17:03 scr\hartech\kids\grapher\images\smiles\19.gif
I.A.... 710 2004-12-19 00:19 scr\hartech\kids\grapher\images\smiles\2.gif
I.A.... 1720 2006-04-25 17:03 scr\hartech\kids\grapher\images\smiles\20.gif
I.A.... 1579 2006-04-25 17:03 scr\hartech\kids\grapher\images\smiles\21.gif
I.A.... 1536 2006-04-25 17:03 scr\hartech\kids\grapher\images\smiles\22.gif
I.A.... 1345 2006-04-25 17:03 scr\hartech\kids\grapher\images\smiles\23.gif
I.A.... 447 2006-08-25 12:41 scr\hartech\kids\grapher\images\smiles\24.gif
I.A.... 505 2004-12-19 00:19 scr\hartech\kids\grapher\images\smiles\3.gif
I.A.... 515 2004-12-19 00:19 scr\hartech\kids\grapher\images\smiles\4.gif
............此处省略14个文件信息
- 上一篇:图像处理单机版java-一个开源项目
- 下一篇:漂亮的jsp登录界面
评论
共有 条评论