pub struct DoublyLinkedList<T> { /* private fields */ }Expand description
Ikki tomonlama bog’langan ro’yxat: har bir tugun oldingi va keyingisini biladi.
✕ ⇄ [10] ⇄ [20] ⇄ [30] ⇄ ✕
^head ^tailIkkala uchdan ham qo’shish/olish O(1) — shuning uchun u deque sifatida ishlaydi.
§Rust darsi: Rc, RefCell, Weak
Rc<T>— bitta qiymatga bir nechta egalik (havolalar sanoqchisi bilan);RefCell<T>— o’zgartirishni ish vaqtida tekshirish (Rcichida&mutolib bo’lmaydi,RefCellshu cheklovni “ichkariga” ko’chiradi);Weak<T>— sanoqchini oshirmaydigan havola; sikllarni oldini oladi.
Bu narx bilan keladi: har murojaatda borrow() tekshiruvi. Shuning uchun
Rustda odatda VecDeque afzal.
§Misol
use rust_algorithms::linked_list::DoublyLinkedList;
let mut l = DoublyLinkedList::new();
l.push_back(2);
l.push_back(3);
l.push_front(1);
assert_eq!(l.to_vec(), vec![1, 2, 3]);
assert_eq!(l.to_vec_rev(), vec![3, 2, 1]);
assert_eq!(l.pop_back(), Some(3));
assert_eq!(l.pop_front(), Some(1));
assert_eq!(l.len(), 1);Implementations§
Source§impl<T> DoublyLinkedList<T>
impl<T> DoublyLinkedList<T>
Sourcepub fn push_front(&mut self, value: T)
pub fn push_front(&mut self, value: T)
Boshiga qo’shadi — O(1).
Source§impl<T: Clone> DoublyLinkedList<T>
impl<T: Clone> DoublyLinkedList<T>
Sourcepub fn to_vec_rev(&self) -> Vec<T>
pub fn to_vec_rev(&self) -> Vec<T>
Oxiridan boshigacha vektor — prev havolalari ishlayotganini ko’rsatadi.
Trait Implementations§
Source§impl<T> Default for DoublyLinkedList<T>
impl<T> Default for DoublyLinkedList<T>
Source§impl<T> Drop for DoublyLinkedList<T>
Rekursiv Drop dan qochish uchun tugunlarni tsiklda bo’shatamiz.
impl<T> Drop for DoublyLinkedList<T>
Rekursiv Drop dan qochish uchun tugunlarni tsiklda bo’shatamiz.
Source§impl<T> FromIterator<T> for DoublyLinkedList<T>
impl<T> FromIterator<T> for DoublyLinkedList<T>
Source§fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Creates a value from an iterator. Read more
Auto Trait Implementations§
impl<T> Freeze for DoublyLinkedList<T>
impl<T> !RefUnwindSafe for DoublyLinkedList<T>
impl<T> !Send for DoublyLinkedList<T>
impl<T> !Sync for DoublyLinkedList<T>
impl<T> Unpin for DoublyLinkedList<T>
impl<T> UnsafeUnpin for DoublyLinkedList<T>
impl<T> !UnwindSafe for DoublyLinkedList<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more