Last active
August 29, 2015 14:11
-
-
Save gsathya/94bf5e6d8ca9abddad64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ src rustc queue.rs | |
queue.rs:4:8: 4:15 error: wrong number of type arguments: expected 1, found 0 | |
queue.rs:4 q: RingBuf, | |
^~~~~~~ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::collections::RingBuf; | |
struct Queue { | |
q: RingBuf, | |
} | |
impl Queue { | |
fn new() -> Queue { | |
Queue{ | |
q: RingBuf::new(), | |
} | |
} | |
fn enque(&self, x: int) { | |
self.q.push_back(x); | |
} | |
fn deque(&self) -> int { | |
return self.q.pop_front().unwrap() | |
} | |
} | |
fn main() { | |
let mut queue = Queue::new(); | |
queue.enque(1i); | |
queue.enque(2i); | |
queue.enque(3i); | |
// Will print 1, 2, 3 | |
for i in (0i, 3i) { | |
let x = queue.deque(); | |
println!("{}", x); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment