-
Rust❤️Stack 구현 implementation & php & C언어코딩Coding/한글Rust강의★내가★공부하려고만듬 2022. 9. 22. 05:40728x90
내가 공부하려고 만듬
한글러스트Rust강의_043⭐️Rust_Stack&(PHP stack implement / Watch from 11:26) #rustlang #php #helix
https://youtu.be/jfKyP03FH6Ypub struct Stack<T> { maxsize: usize, items: Vec<T>, } impl<T> Stack<T> { pub fn with_capacity(maxsize: usize) -> Self { Self { maxsize, items: Vec::with_capacity(maxsize), } } pub fn pop(&mut self) -> Option<T> { self.items.pop() } pub fn push(&mut self, item: T) -> bool { if self.items.len() == self.maxsize { return false; } self.items.push(item); return true; } pub fn size(&self) -> usize { self.items.len() } pub fn peek(&self) -> Option<&T> { self.items.last() } } #[cfg(test)] mod tests { #[test] fn test_new_with_capacity() { let stack = super::Stack::<u32>::with_capacity(10); assert_eq!(10, stack.items.capacity()); } #[test] fn test_pop(){ let mut stack = super::Stack::<u32>::with_capacity(1); stack.push(1u32); assert_eq!(Some(1u32), stack.pop()); assert_eq!(None, stack.pop()); } #[test] fn test_push() { let mut stack = super::Stack::<u32>::with_capacity(1); stack.push(32u32); assert_eq!(Some(&32u32), stack.peek()); assert_eq!(1, stack.size()); } #[test] fn test_push_maxsize() { let mut stack = super::Stack::<u32>::with_capacity(1); assert_eq!(true, stack.push(1u32)); assert_eq!(Some(&1u32), stack.peek()); assert_eq!(false, stack.push(2u32)); } #[test] fn test_size() { let mut stack = super::Stack::<u32>::with_capacity(1); assert_eq!(0, stack.size()); stack.push(1u32); assert_eq!(1, stack.size()); } }
https://chercher.tech/rust/stack-rust
https://gist.github.com/Archina/612de166242694f9e9e3ccb6f1bdb4ac
PHP
https://github.com/YoungHaKim7/Php_Lang/tree/main/execise/stack
C언어
https://github.com/YoungHaKim7/c_project/tree/main/exercise/002stack
Rust로 queues 구현하기
https://github.com/savish/queues
반응형'코딩Coding > 한글Rust강의★내가★공부하려고만듬' 카테고리의 다른 글
Sizedness in Rust집중훈련?Size 이런거 공부하기 (0) 2022.09.26 Rust❤️Sized Trait, Sized in Generics, ?sized type 러스트에 나오는 ?Size의 의미 (0) 2022.09.25 C언어 분석 기초 (0) 2022.09.25 A Rust function that can only be called 3 times - Unstable Rust (0) 2022.09.24 읽어본 것 중 최고의 소스코드는?❤️ (0) 2022.09.15 rust로 만든 에디터 Helix 🧬keymap❤️ (0) 2022.09.15 Rust❤️Vulkan 게임개발 기초 (0) 2022.09.14 러스트 게임 개발 - 언리얼 엔진❤️ __내가 기다리던 소식 ㅎㅎ (0) 2022.09.13