當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Rust LinkedList.contains用法及代碼示例

本文簡要介紹rust語言中 alloc::collections::linked_list::LinkedList.contains 的用法。

用法

pub fn contains(&self, x: &T) -> bool where    T: PartialEq<T>,

如果 LinkedList 包含等於給定值的元素,則返回 true

此操作應在 O(n) 時間內計算。

例子

use std::collections::LinkedList;

let mut list: LinkedList<u32> = LinkedList::new();

list.push_back(0);
list.push_back(1);
list.push_back(2);

assert_eq!(list.contains(&0), true);
assert_eq!(list.contains(&10), false);

相關用法


注:本文由純淨天空篩選整理自rust-lang.org大神的英文原創作品 alloc::collections::linked_list::LinkedList.contains。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。