-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlib.rs
More file actions
22 lines (20 loc) · 807 Bytes
/
lib.rs
File metadata and controls
22 lines (20 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//! Implement a `Queue` trait and two structures implementing it `Fifo` (first in first out) and `Lifo` (last in first out).
//!
//! Constrains:
//! - follow the trait implemented below (you can add methods if you like)
//! - implement conversion from &[T]
//! - implement conversion into Vec<T>
enum Error {}
trait Queue<T> {
fn with_capacity(cap: usize) -> Self;
// this function returns a reference to the next element to pop
fn peek(&self) -> Option<&T>;
// this function must pop the next item according
// to the kind of queue it is
fn pop(&mut self) -> Option<T>;
// this function must put the item in the queue
// Error has to be defined
fn put(&mut self, item: T) -> Result<(), Error>;
fn is_empty(&self) -> bool;
fn is_full(&self) -> bool;
}