master > master: code-rust - `.contains` methode für stacks hinzugefügt

This commit is contained in:
RD 2022-04-14 11:55:31 +02:00
parent 07b214bc24
commit 5ce805c543
1 changed files with 6 additions and 1 deletions

View File

@ -18,7 +18,7 @@ pub struct Stack<T> {
}
impl<T> Stack<T>
where T: Clone + ToString {
where T: Clone + ToString + Eq {
/// Creates new typed instance of stack.
pub fn new() -> Stack<T> {
return Stack {
@ -53,6 +53,11 @@ where T: Clone + ToString {
return element;
}
/// checks if element in stack:
pub fn contains(self: &Self, element: &T) -> bool {
return self.elements.contains(element);
}
/// convert entries to strings
#[allow(dead_code)]
fn repr(self: &Self) -> Vec<String> {