单向链表的实现
来源:互联网 发布:手机联系淘宝人工客服 编辑:程序博客网 时间:2024/05/29 18:16
/*单向链表的实现*/
class Node{
private String data;
private Node next;
public Node(String data){
this.data = data;
}
public String getData(){
return this.data;
}
public Node getNext() {
return next;
}
public void setNext(Node next) {
this.next = next;
}
}
public class LinkDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Node root = new Node("火车头");
Node n1 = new Node("第一节车厢");
Node n2 = new Node("第二节车厢");
Node n3 = new Node("第三节车厢");
root.setNext(n1);
n1.setNext(n2);
n2.setNext(n3);
prinNode(root);
}
public static void prinNode(Node node){
System.out.println(node.getData()+" ");
if(node.getNext()!=null){
prinNode(node.getNext());
}
}
}
class Node{
private String data;
private Node next;
public Node(String data){
this.data = data;
}
public String getData(){
return this.data;
}
public Node getNext() {
return next;
}
public void setNext(Node next) {
this.next = next;
}
}
public class LinkDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Node root = new Node("火车头");
Node n1 = new Node("第一节车厢");
Node n2 = new Node("第二节车厢");
Node n3 = new Node("第三节车厢");
root.setNext(n1);
n1.setNext(n2);
n2.setNext(n3);
prinNode(root);
}
public static void prinNode(Node node){
System.out.println(node.getData()+" ");
if(node.getNext()!=null){
prinNode(node.getNext());
}
}
}
0 0
- 单向链表的实现
- 单向链表的实现
- 单向链表的实现
- 单向链表的实现
- 单向链表的实现
- 单向链表的实现
- 单向链表实现
- 单向链表实现
- C语言单向链表的实现
- java 单向链表的实现
- C#单向链表的实现
- C语言实现的单向链表
- 单向链表的c++实现
- 数据结构练习--单向链表的实现
- 单向链表的C语言实现
- 单向链表的C++实现
- 单向循环链表的C++实现
- 反转单向链表的实现
- JAR还原
- AVI文件的读取并显示
- SSH一些问题解决
- 创建并使用多个对象
- linux c struct tm宏定义时有时报dereferencing pointer to incomplete type错误,可以将包含头文件改为#include <sys/timeb.h>
- 单向链表的实现
- springSecurity分离资源服务器分析
- Tricks(十九)—— 获得 list of lists 每一列的最大最小值
- import Tkinter的时候报错
- 大数阶乘(10000级别) 51Nod 1057
- java 继承中构造方法和类成员方法间的关系
- leetcode-Excel Sheet Column Title
- 反向代理分离资源服务器分析
- 使用TimerTask进行调度