Rustアンチスレ (202レス)
上
下
前
次
1-
新
52
: 2020/08/28(金)17:13
ID:BFWbiW8H(2/2)
AA×
[
240
|
320
|480|
600
|
100%
|
JPG
|
べ
|
レス栞
|
レス消
]
52: [sage] 2020/08/28(金) 17:13:22.85 ID:BFWbiW8H リンクリストを実装するのはこんなに難しく、 nextメンバの型は、Option<Rc<RefCell<Node<T>>>> となる : type Link<T> = Rc<RefCell<Node<T>>>; #[derive(Debug)] struct Node<T> { value: T, prev: Option<Link<T>>, next: Option<Link<T>>, } impl<T> LinkedList<T> { pub fn append(&mut self, v: T) { let node = Node::new(v); match self.tail.take() { Some(old_tail) => { old_tail.borrow_mut().next = Some(Rc::clone(&node)); node.borrow_mut().prev = Some(old_tail); } None => { // first element debug_assert_eq!(self.len(), 0); self.head = Some(Rc::clone(&node)); } } self.tail = Some(node); self.length += 1; } } http://mevius.5ch.net/test/read.cgi/tech/1509028624/52
リンクリストを実装するのはこんなに難しく メンバの型は となる
上
下
前
次
1-
新
書
関
写
板
覧
索
設
栞
歴
あと 150 レスあります
スレ情報
赤レス抽出
画像レス抽出
歴の未読スレ
AAサムネイル
ぬこの手
ぬこTOP
0.037s