java实现单链表基本操作

[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();
}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值