자료구조/by swift

자료구조/by swift

swift PriorityQueue 구현

swift로 우선순위 큐를 구현했습니다. /* base on : Array, binary Tree */ class PriorityQueue{ private var elements: [T] = [] private let compare: (T, T) -> Bool var top: T?{elements.first} var isEmpty: Bool{elements.isEmpty} var count: Int{elements.count} init(){ compare = {$0 Bool){ self.compare = compare // 정렬 기준을 받아서 덮어쓰기 } func pus..

자료구조/by swift

swift Double-LinkedList 구현

https://en.wikipedia.org/wiki/Doubly_linked_list Doubly linked list - Wikipedia From Wikipedia, the free encyclopedia Linked list data structure In computer science, a doubly linked list is a linked data structure that consists of a set of sequentially linked records called nodes. Each node contains three fields: two link fields (refe en.wikipedia.org 위키피디아에서 어떤 메소드를 갖고 있어야 하며, 어떤 프로퍼티가 있는지만 확인하..

자료구조/by swift

swift queue 구현

저번에 이어서 이번에는 queue 구현 코드이다. class Queue{ private var backStack = Stack() private var frontStack = Stack() var isEmpty : Bool{ return backStack.isEmpty && frontStack.isEmpty } var front : Any?{ guard backStack.isEmpty || frontStack.isEmpty else {return nil} if !frontStack.isEmpty {return frontStack.top} while !backStack.isEmpty { if let top = backStack.pop() { frontStack.push(top) } } return fron..

자료구조/by swift

swift stack 구현

swift로 stack을 구현해봤습니다. struct Stack{ private var elements: [T] = [] mutating func push(_ element : T){ elements.append(element) } mutating func pop() -> T?{ return elements.popLast() ?? nil } var top: T?{ return elements.last ?? nil } var isEmpty : Bool{ return elements.isEmpty } } 위와 같이 구현해봤는데.. 흠 좋은 거 같기도 ㅎ고 아닌 거 같기도 하고 ..

견우직녀달
'자료구조/by swift' 카테고리의 글 목록