代码实现了双向链接列表。
class ConcurrentSortedList {
private class Node {
int value;
Node prev;
Node next;
Node() {}
Node(int value, Node prev, Node next) {
this.value = value; this.prev = prev; this.next = next;
}
}
private final Node head;
private final Node tail;
public ConcurrentSortedList() {
head = new Node(); tail = new Node();
head.next = tail; tail.prev = head;
}
}
我在转换行时遇到问题:
head.next =尾巴; tail.prev = head;
到目前为止,我的代码是:
(defrecord Node
[value prev next])
(defrecord ConcurrentSortedList
[head tail])
(defn make-concurrent-sortedlist [opts]
(let [lst (->ConcurrentSortedList (Node.) (Node.))
lst (assoc-in lst [:head :next] (:tail lst))
lst (assoc-in lst [:tail :prev] (:head lst))
;; todo
]))