{ older:Vec 赞 踩 Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。
Rust 泛型结构体
fn main(){
let mut q1 : Queue<u8> = Queue::new();
q1.push(3);
q1.push(4);
println!("{:#?}",q1);
println!("{}",q1.is_empty());
}
#[derive(Debug,Clone)]
pub struct Queue<T>{
older:Vec<T>,
younger: Vec<T>
}
impl <T> Queue<T> {
pub fn new() -> Self {
Queue{older:Vec::new(), younger: Vec::new()}
}
pub fn push(&mut self,t:T){
self.younger.push(t);
}
pub fn is_empty(&self)-> bool{
self.younger.is_empty() && self.older.is_empty()
}
}