1. 链表 -- 增
2. 链表 -- 删
3. 链表 -- 遍历
4. 链表 -- 反向遍历
5. 链表 -- 反转链表
DEMO :
package lime.xiaoniu; /** * Created by LimeOracle on 2017/11/17. */ public class DevilList { public static void main(String[] args){ DevilList list = null; for(int i = 1;i < 11;i++){ list = DevilList.addList(list, i); } for(int i = 10;i > 0;i--) { list = deleteList(list, i); DevilList.inOrder(list); System.out.println(); } } private Integer data; private DevilList next; public DevilList(Integer data) { this.data = data; } //添加 public static DevilList addList(DevilList head , Integer data){ if(null == head){ return new DevilList(data); } head.next = addList(head.next,data); return head; } //遍历 public static void inOrder(DevilList head){ if(null == head){ return; } System.out.print(head.data + " "); inOrder(head.next); } //反向遍历 public static void reversalData(DevilList head){ if(null == head){ return; } reversalData(head.next); System.out.print(head.data + " "); } //反转 public static DevilList reversalList(DevilList head){ if(null == head || null == head.next){ return head; } DevilList reversalHead = reversalList(head.next); head.next.next = head; head.next = null; return reversalHead; } //删除 public static DevilList deleteList(DevilList head,int data){ if(null == head){ return head; } if(data == head.data){ head = head.next; }else{ head.next = deleteList(head.next,data); } return head; } @Override public String toString() { return "ReversalList{" + "data=" + data + ", next=" + next + '}'; } }
啦啦啦
本文详细介绍了一种链表数据结构的基本操作方法,包括链表的添加、遍历、反向遍历、反转及删除等核心功能,并通过Java代码实现具体演示。
2037

被折叠的 条评论
为什么被折叠?



