java语言编写的单链表 出现了好多错误 请大虾帮忙修改一下 本帖最后由 dollyn 于 2010-03-31 15:01:32 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Link里全是问题;改好的代码如下package csdn;public class Link{ private Node first = null;//链表表头 public Link() { this.first = null; } public boolean isEmpty() { if(this.first == null) { return true; } else { return false; } } public void insertHeadNode(int data) { Node node = new Node(data); if(this.first == null) { this.first = node; } else { Node tempNode = this.first; this.first = node; this.first.next = tempNode; } } public Node deleteHeadNode() { if(this.first == null) { return null; } else { Node head = this.first; Node next = this.first.next; this.first = next; head = null; return head; } } public Node findNode(Node node, int k) { if(this.first == null) { System.out.println("this link is empty!"); return null; } else { if(node.data == k) { return node; } else { node = node.next; return this.findNode(node, k); } } } public void displayLink (Node node) { if(this.first == null) { System.out.println("this link is empty!"); return; } if(node != null) { node.NodeDisplay(); node = node.next; this.displayLink(node); } } public static void main(String[] args) { // TODO Auto-generated method stub Link aaa = new Link(); aaa.insertHeadNode(4); aaa.insertHeadNode(6); aaa.insertHeadNode(8); aaa.insertHeadNode(45); aaa.insertHeadNode(876);// aaa.deleteHeadNode(); aaa.displayLink(aaa.first); Node node = aaa.findNode(aaa.first, 8); System.out.println(node.data + " next = " + node.next.data); }} Link里全是问题,改好的代码如下package csdn;public class Link{ private Node first = null;//链表表头 public Link() { this.first = null; } public boolean isEmpty() { if(this.first == null) { return true; } else { return false; } } public void insertHeadNode(int data) { Node node = new Node(data); if(this.first == null) { this.first = node; } else { Node tempNode = this.first; this.first = node; this.first.next = tempNode; } } public Node deleteHeadNode() { if(this.first == null) { return null; } else { Node head = this.first; Node next = this.first.next; this.first = next; head = null; return head; } } public Node findNode(Node node, int k) { if(this.first == null) { System.out.println("this link is empty!"); return null; } else { if(node.data == k) { return node; } else { node = node.next; return this.findNode(node, k); } } } public void displayLink (Node node) { if(this.first == null) { System.out.println("this link is empty!"); return; } if(node != null) { node.NodeDisplay(); node = node.next; this.displayLink(node); } } public static void main(String[] args) { // TODO Auto-generated method stub Link aaa = new Link(); aaa.insertHeadNode(4); aaa.insertHeadNode(6); aaa.insertHeadNode(8); aaa.insertHeadNode(45); aaa.insertHeadNode(876);// aaa.deleteHeadNode(); aaa.displayLink(aaa.first); Node node = aaa.findNode(aaa.first, 8); System.out.println(node.data + " next = " + node.next.data); }} 今天做的赶集网的笔试题,大家有兴趣讨论一下 一个算法问题 工程复制问题 如何用正侧来分析这样的数据? 给个代码 将ResultSet转成HashTable,并将HashTable里的值逐一显示出来 請問怎麼樣得到 操作操作系統機器 的名稱 连个边都找不着,真闷,学JAVA,是不是要配好服务器先呀,你们都用什么呢 如何设计软件包的异常处理? 如何将一个值赋给long形变量? 救我!! 弄的我茶饭不思的多线程理解! 简单socket通信问题,急~
{
private Node first = null;//链表表头
public Link()
{
this.first = null;
}
public boolean isEmpty()
{
if(this.first == null)
{
return true;
}
else
{
return false;
}
}
public void insertHeadNode(int data)
{
Node node = new Node(data);
if(this.first == null)
{
this.first = node;
}
else
{
Node tempNode = this.first;
this.first = node;
this.first.next = tempNode;
}
}
public Node deleteHeadNode()
{
if(this.first == null)
{
return null;
}
else
{
Node head = this.first;
Node next = this.first.next;
this.first = next;
head = null;
return head;
}
}
public Node findNode(Node node, int k)
{
if(this.first == null)
{
System.out.println("this link is empty!");
return null;
}
else
{
if(node.data == k)
{
return node;
}
else
{
node = node.next;
return this.findNode(node, k);
}
}
}
public void displayLink (Node node)
{
if(this.first == null)
{
System.out.println("this link is empty!");
return;
} if(node != null)
{
node.NodeDisplay();
node = node.next;
this.displayLink(node);
}
}
public static void main(String[] args)
{
// TODO Auto-generated method stub
Link aaa = new Link();
aaa.insertHeadNode(4);
aaa.insertHeadNode(6);
aaa.insertHeadNode(8);
aaa.insertHeadNode(45);
aaa.insertHeadNode(876);
// aaa.deleteHeadNode();
aaa.displayLink(aaa.first);
Node node = aaa.findNode(aaa.first, 8);
System.out.println(node.data + " next = " + node.next.data);
}}
{
private Node first = null;//链表表头
public Link()
{
this.first = null;
}
public boolean isEmpty()
{
if(this.first == null)
{
return true;
}
else
{
return false;
}
}
public void insertHeadNode(int data)
{
Node node = new Node(data);
if(this.first == null)
{
this.first = node;
}
else
{
Node tempNode = this.first;
this.first = node;
this.first.next = tempNode;
}
}
public Node deleteHeadNode()
{
if(this.first == null)
{
return null;
}
else
{
Node head = this.first;
Node next = this.first.next;
this.first = next;
head = null;
return head;
}
}
public Node findNode(Node node, int k)
{
if(this.first == null)
{
System.out.println("this link is empty!");
return null;
}
else
{
if(node.data == k)
{
return node;
}
else
{
node = node.next;
return this.findNode(node, k);
}
}
}
public void displayLink (Node node)
{
if(this.first == null)
{
System.out.println("this link is empty!");
return;
} if(node != null)
{
node.NodeDisplay();
node = node.next;
this.displayLink(node);
}
}
public static void main(String[] args)
{
// TODO Auto-generated method stub
Link aaa = new Link();
aaa.insertHeadNode(4);
aaa.insertHeadNode(6);
aaa.insertHeadNode(8);
aaa.insertHeadNode(45);
aaa.insertHeadNode(876);
// aaa.deleteHeadNode();
aaa.displayLink(aaa.first);
Node node = aaa.findNode(aaa.first, 8);
System.out.println(node.data + " next = " + node.next.data);
}}