成人版java数据结构之单链表I建立和遍历

package org.huchao.baseStructs;
/**
 * 成人版java数据结构之单链表的建立和遍历
 * @author huchao
 * @since 2007.11.
 */
public class Node1 {

 private Object item;
 
 private Node1 next;
 
 public Node1(Object newItem){
  item = newItem;
  next = null;
 }
 
 public Node1(Object newItem,Node1 nextNode){
  item = newItem;
  next = nextNode;
 }
 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Node1 head = new Node1(new String("上校"));
  Node1 second = new Node1(new String("上尉"),head);
  Node1 third = new Node1(new String("中尉"),second);
  System.out.println("当兵的过河,河里有吃球鱼,该怎么过呢?");
  for(Node1 curr = third;null != curr;curr = curr.getNext()){
   if(isLast(curr)){
    System.out.print(curr.getItem() + "走在最后面");
   }else
   System.out.println(curr.getItem() + "的P眼被" + curr.getNext().item + "的的JJ插入");
   
  }
 }

 public static boolean isLast(Node1 node){
  if(null == node.getNext())
   return true;
  return false;
 }
 public Object getItem() {
  return item;
 }

 public void setItem(Object item) {
  this.item = item;
 }

 public Node1 getNext() {
  return next;
 }

 public void setNext(Node1 next) {
  this.next = next;
 }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值