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..
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 위키피디아에서 어떤 메소드를 갖고 있어야 하며, 어떤 프로퍼티가 있는지만 확인하..
저번에 이어서 이번에는 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..
내 입맛대로 stack 구현하기 1. empty 2. push 3. pop 4. size push를 할 때 자신의 입맛대로 매개변수 만들어서 넣으시면 됩니다. node에는 해당 문제에 따라서 저장할 값을 추가적으로 넣어주시면 됩니다. #include #include typedef long long ll; typedef struct node{ char value; int cnt;//몇 개 쌓아왔는지 struct node* pre; }node; typedef struct stack{ node *top; ll size; }stack; ll size(stack* s){ return s->size; } node* top(stack*s){ return s->top; } bool empty(stack*s){ retu..
흠.. 일단 그냥 막 내가 쓰고 싶은 대로 구현하긴 했다. prev, next를 통해서 전과 후로 갈 수 있고 insert,delete가 O(1)에 해결 가능하다. insert는 여러 버전이 있는데, index에 추가하는 것과, 가리키고 있는 node에 insert하는 것과, 제일 앞에 insert, 그리고 제일 뒤에 insert을 넣는 버전이 있다. #include typedef long long ll; typedef struct node{ char value;//값 struct node* prev;//전 struct node* next;//다음 }node; typedef struct Linkedlist{ node* front;//맨 앞 node* back;//맨 뒤 ll size;//크기 }Linke..
c++ vector를 c언어에서도 쓰고 싶어서 간단하게 만들어 봤습니다. #include typedef long long ll; typedef struct node{//해당하는 값을 arr로 갖는다. int v; }node; typedef struct vector{//인덱스 접근 가능해야 하며, size 존재, back, pop_back, node* arr;//값을 저장하는 곳 ll size;//크기 ll capacity;//전체 크기 }vector; void init(vector *q){ q->arr=(node *)malloc(sizeof(node)*(64)); q->size=0; q->capacity=64;//초기 크기 64개 } void push_back(vector *q,int v){//v가 추가..