有序表
- TreeMap
- TreeSet
哈希表
单向链表
- 反转单向、双向链表
public static Node reverseLinkedList(Node head) {
if (head == null) {
return null;
}
Node pre = null;
Node next = null;
while (head != null) {
//先用next保存head的下一个节点的信息
next = head.next;
head.next = pre;
//节点的前驱和节点都后移,继续遍历
pre = head;
head = next;
}
return pre;
}
public static DoubleNode reverseDoubleLinkedList(DoubleNode head) {
if (head == null) {
return null;
}
DoubleNode tmp = null;
//res的作用仅仅是记录head的上一个节点
DoubleNode res = null;
while (head != null) {
//先用tmp保持后继节点,然后交换前后节点
tmp = head.next;
head.next = head.pre;
head.pre = tmp;
//记录res
res = head;
//head指向tmp保存的原节点的后继节点,即向后推进一个节点
head = tmp;
}
return res;
}
- 打印有序公共部分
- 回文结构【利用栈逆序打出】