
数据结构和算法
双木L
菜鸟程序猿一枚
展开
-
力扣解题:如何用栈实现队列,用队列实现栈?
1)队列的基本实现 /** * 队列实现 */ Queue<Integer>queue=new LinkedList<>(); //添加元素 queue.offer(1); queue.offer(2); queue.offer(3); //第二种方式添加 /*queue.add(1); queue.add(2); queue.add(3);*/ //取出元素 Integer poll1 = queue.poll(); System.out.println(poll1); /原创 2021-04-13 21:29:13 · 164 阅读 · 0 评论 -
五种最简单常用的排序方法Demo
1.冒泡排序 public static void main(String[] args) { int nums []=new int[] {5,4,6,1,2,8,3,7,9,0}; bubbleSort(nums); System.out.println(Arrays.toString(nums)); } //冒泡排序 private static void bubble...原创 2019-05-18 21:39:43 · 731 阅读 · 0 评论