[quote]数据结构是计算机程序设计的重要理论和技术基础,它所讨论的内容和提倡的技术方法[/quote]
/**
* @(#)Node.java
*
*
* @author
* @version 1.00 2009/2/22
*/
public class Node {
public int i;
public double j;
Node next;
public Node(int a,double b) {
this.i=a;
this.j=b;
this.next=null;
}
public void NodeDisplay(){
System.out.println ("{"+i+j+"}");
}
}
/**
* @(#)LinkNode.java
*
*
* @author
* @version 1.00 2009/2/22
*/
public class LinkNode {
private Node first;
public LinkNode() {
this.first=null;
}
public boolean isEmpty(){
return first==null;
}
public void insertHeadNode(int a,double b){
Node n=new Node(a,b);
n.next=first;
first=n;
}
public Node deleteHeadNode(){
Node temp=first;
first=first.next;
return temp;
}
public void findNode(int k){
Node current = first;
int i=1;
while(current != null)
{
if(i==k){
System.out.print ("节点"+i+"已找到,为:");
current.NodeDisplay();
}
current = current.next;
i++;
}
}
public void displayLinkNode(){
Node current = first;
while(current != null)
{
current.NodeDisplay();
current = current.next;
}
}
public static void main (String[] args) {
LinkNode ll=new LinkNode();
ll.insertHeadNode(12,33.33);
ll.insertHeadNode(52,53.53);
ll.insertHeadNode(62,73.83);
ll.insertHeadNode(34,65.76);
ll.deleteHeadNode();
ll.findNode(3);
ll.displayLinkNode();
}
}