갬발자의 프로그래밍40 [자료구조] Queue 구현하기 큐(queue)는 컴퓨터의 기본적인 자료 구조의 한가지로, 먼저 집어 넣은 데이터가먼저 나오는 FIFO (First In First Out)구조로 저장하는 형식을 말한다. 출처 - 위키백과 구현하기 class Queue { private size = 0; private currSize = 0; private queue: Array = []; private first = 0; private rear = 0; constructor(size: number) { this.size = size; } enqueue(value: T): Queue { if (this.currSize >= this.size) { throw new Error('queue is overflow'); } this.queue[this.rear.. 2021. 3. 31. [자료구조] Linked List 직접 구현하기. Linked list - 각 노드가 데이터와 포인터를 가지고 한 줄로 연결되어 있는 방식으로 데이터를 저장하는 자료 구조이다. (위키백과) [구현하기] class MyNode { public next: null | undefined | MyNode; public value: T; constructor(value: T) { this.value = value; this.next = null; } } class LinkedList { private head: MyNode; private tail: MyNode; private length = 0; constructor(value: T) { this.head = new MyNode(value); this.tail = this.head; this.length = .. 2021. 3. 30. [자료구조] Stack 직접 구현하기 stack은 후입선출(LIFO)의 자료 구조이다. 즉, 마지막에 넣은 데이터가 가장 먼저 꺼내진다. [구현하기] class Stack { private stack: Array = []; private max = 0; private len = 0; constructor(max: number) { this.max = max; } top(): T { return this.stack[this.len - 1]; } pop(): Stack { if (this.len === 0) throw new Error('stack is empty'); this.stack.splice(this.len - 1, 1); this.len--; return this; } push(value: T): Stack { if (this.len.. 2021. 3. 28. [Javascript] this 의미, 암시적바인딩 vs 명시적바인딩 (call, apply, bind, new, 화살표함수) this란 객체를 참조하는 키워드다. 하지만 다른 언어와 다르게 런타임 바인딩 되기때문에 this의 값은 함수를 호출한 위치에서 결정된다. [기본바인딩] function foo() { console.log(this); } foo(); //// window 기본바인딩은 global적으로 바인딩이 되는것을 말하며 브라우저 상에서는 window 객체를 가르킨다. [암시적 바인딩] window.a = 'window'; function foo() { console.log(this.a); } const obj = { a:1, foo: foo } obj.foo() // 1 foo() // window 함수가 f호출되는 위치에서 this가 바인딩 되어진다. 위의 경우 this가 { a: 1, foo: foo } 객체에.. 2021. 3. 11. 이전 1 2 3 4 ··· 10 다음