链表反转

public static LinkListTest reverse(LinkListTest link) {
if (link == null || link.getNext() == null) {
return link; }
LinkListTest curNode = link.getNext(); link.setNext(null); while (curNode != null) {
LinkListTest nextNode = curNode.getNext(); curNode.setNext(link); link = curNode; curNode = nextNode; }
return link;}

栈实现队列

public class QueueDemo {

  1. //先进后出 实现先进先出 private Stack<Integer> stack = null; private Stack<Integer> temp = null;<br /> public QueueDemo() {<br /> stack = new Stack<>(); temp = new Stack<>(); }
  2. /*<br /> */ public void push(Integer value) {<br /> stack.push(value);// 1 2 3 4 }
  3. public Integer pop() {<br /> Integer result = null;// temp.clear(); // 拿出来 放进去 如何优化 空判断 if (!temp.isEmpty()){<br /> result =temp.pop(); }else {<br /> while (!stack.isEmpty()){<br /> temp.push(stack.pop()); }<br /> if (!temp.isEmpty()){<br /> result = temp.pop(); }<br /> }<br /> return result; }
  4. public static void main(String[] args) {<br /> QueueDemo queueDemo = new QueueDemo(); queueDemo.push(1); queueDemo.push(2); queueDemo.push(3); queueDemo.push(4);<br /> System._out_.println(queueDemo.pop()); System._out_.println(queueDemo.pop()); System._out_.println(queueDemo.pop()); System._out_.println(queueDemo.pop()); System._out_.println(queueDemo.pop());<br /> }

}

冒泡排序

/当前循环如果没有变化,说明
/public int[] maopaoSort(int[] nums) {
boolean hasChange = true; for (int i = 0; i < nums.length && hasChange; i++) {
hasChange = false; for (int j = 0; j < nums.length - 1 - i; j++) {
if (nums[j] > nums[j + 1]) {
hasChange = true; int temp = nums[j]; nums[j] = nums[j + 1]; nums[j + 1] = temp; }
}
}
System.out.println(Arrays.toString(nums)); return nums;}

插入排序

public int[] charuSort(int[] nums) {
for (int i = 1, j, current; i < nums.length; i++) {
current = nums[i]; for (j = i - 1; j >= 0 && nums[j] > current; j—) {
nums[j + 1] = nums[j]; }
System.out.println(j); nums[j + 1] = current; }
System.out.println(Arrays.toString(nums)); return nums;}

计算二叉树深度

回文判断