队列数据结构可以详细学习
package com.queue;
import java.util.PriorityQueue;
import java.util.Queue;
public class QueueTest {
public static void main(String[] args) {
Queue queue = new PriorityQueue();
queue.offer(-2);
queue.offer(-10);
queue.offer(9);
queue.offer(3);
System.out.println(queue);
Integer num = null;
while ((num = (Integer) queue.poll())!=null){
System.out.println(num);
}
System.out.println(queue);
}
}
什么是栈
栈的使用方法
package com.deque;
import java.util.ArrayDeque;
import java.util.Deque;
public class ArrayDequeTest {
public static void main(String[] args) {
Deque stack = new ArrayDeque();
stack.push("sss");
stack.push("fff");
stack.push("hhh");
//System.out.println(stack);
// String person = null;
// while ((person = (String) stack.pop()) != null) {
// System.out.println(person);
// }
// System.out.println(stack);
// }
int stackSize = stack.size();
for(int i = 0;i < stackSize; i++){
String person = (String) stack.pop();
System.out.println(person);
}
}
}
队列使用方法
package com.queue;
import java.util.ArrayDeque;
import java.util.Deque;
public class QuequTest02 {
public static void main(String[] args) {
Deque stack = new ArrayDeque();
stack.push("sss");
stack.push("fff");
stack.push("hhh");
int stackSize = stack.size();
for(int i = 0;i < stackSize; i++){
String person = (String) stack.poll();
System.out.println(person);
}
}
}
package com.queue;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedList;
public class QuequTest02 {
public static void main(String[] args) {
Deque stack = new LinkedList();
stack.push("sss");
stack.push("fff");
stack.push("hhh");
int stackSize = stack.size();
for(int i = 0;i < stackSize; i++){
String person = (String) stack.poll();
System.out.println(person);
}
}
}