diff --git a/notes/算法.md b/notes/算法.md index 4d818bad..58f49e4a 100644 --- a/notes/算法.md +++ b/notes/算法.md @@ -446,52 +446,6 @@ public class ListQueue implements MyQueue { } ``` -```java -public class Queue { - private Node first; - private Node last; - int N = 0; - - private class Node { - Item item; - Node next; - } - - public boolean isEmpty() { - return N == 0; - } - - public int size() { - return N; - } - - public void add(Item item) { - Node newNode = new Node(); - newNode.item = item; - newNode.next = null; - if (isEmpty()) { - last = newNode; - first = newNode; - } else { - last.next = newNode; - last = newNode; - } - N++; - } - - public Item remove() throws Exception { - if (isEmpty()) - throw new Exception("queue is empty"); - Node node = first; - first = first.next; - N--; - if (isEmpty()) - last = null; - return node.item; - } -} -``` - # 三、排序 待排序的元素需要实现 Java 的 Comparable 接口,该接口有 compareTo() 方法,可以用它来判断两个元素的大小关系。