-
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-rustStack in Rust
A stack is a data structure with LIFO features for the last in, first out. Take the above picture borrowed from Wikipedia as an example. In the case of the fifth picture, if you want to get 2, you must first remove 3, 4, and 5 from the stack.
chercher.tech
https://gist.github.com/Archina/612de166242694f9e9e3ccb6f1bdb4acImplementing a simple Stack within Rust
Implementing a simple Stack within Rust. GitHub Gist: instantly share code, notes, and snippets.
gist.github.com
PHP
https://github.com/YoungHaKim7/Php_Lang/tree/main/execise/stackGitHub - YoungHaKim7/Php_Lang
Contribute to YoungHaKim7/Php_Lang development by creating an account on GitHub.
github.com
C언어
https://github.com/YoungHaKim7/c_project/tree/main/exercise/002stackGitHub - YoungHaKim7/c_project: c_project
c_project. Contribute to YoungHaKim7/c_project development by creating an account on GitHub.
github.com
Rust로 queues 구현하기
https://github.com/savish/queuesGitHub - savish/queues: An implementation of various FIFO queues in Rust.
An implementation of various FIFO queues in Rust. Contribute to savish/queues development by creating an account on GitHub.
github.com
반응형'코딩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