创建单链表
来源:互联网 发布:科比职业生涯场均数据 编辑:程序博客网 时间:2024/05/17 06:13
public class Lnode {
public String key;
public Lnode next;
public Lnode(String key)
{
this.key=key;
this.next=null;
}
public Lnode(String key,Lnode next)
{
this.key=key;
this.next=next;
}
public String getKey()
{
return key;
}
}
import org.omg.CORBA.PUBLIC_MEMBER;
public class MyList {
private Lnode head=null;
private Lnode tail=null;
public void initiate(Lnode node)
{
head=node;
head.next=tail;
}
public void addToList(Lnode node) {
if (head == null) {
initiate(node);
}
else{
Lnode tmp = head;
head = node;
node.next = tmp;
}
}
public Lnode getHead() {
return head;
}
public void print(MyList myLisTest)
{
Lnode tmp=null;
for (tmp=myLisTest.getHead();tmp!=null;tmp=tmp.next) {
System.out.print(tmp.getKey());
}
}
public static void main(String[] args)
{
System.out.println("begin");
MyList myList = new MyList();
Lnode node1 = new Lnode("1");
Lnode node2 = new Lnode("2");
System.out.println("can can new node");
myList.addToList(node1);
myList.addToList(node2);
System.out.println("can add node");
myList.print(myList);
}
}
- 创建单链表
- 创建单链表
- 创建单链表
- 创建单链表
- 单链表创建
- 创建单链表
- 创建单链表
- 创建二叉树 创建单链表
- 单链表-用尾插法创建单链表
- 单链表的创建
- 1.单链表的创建
- 单链表的创建
- 前插法创建单链表
- 尾插法创建单链表
- 创建单链表2
- 创建单链表3
- 单链表创建,插入,删除
- 单链表创建、排序、合并
- 深入理解java异常处理机制
- 【php】2、学生管理系统-登陆进去
- 两个不同的人生
- 华为oj之过河卒
- Docker实战:更轻松、更愉快、更高效
- 创建单链表
- 用户角色权限模式的图书销售系统
- 关于开发板用tftp下载
- C语言的数制
- 函数指针作为参数(以冒泡排序qsort为例)
- 【转】51单片机精确延迟程序
- Linux开发常用命令
- [G+smo]单元和边界迭代器 iterators
- JSP中自定义标签