🐷 data_structure_JS
INTRODUCTION
JS 에 네이티브하게 존재하지 않는 자료구조들을 구현한 라이브러리입니다.
또한 자료구조 시각화 웹 뷰 프론트엔드가 구현되어 있어 학습 용도 등으로 활용 가능합니다.
DEPENDENCY
-
jest
-
expect
테스트를 위해 jest 와 expect를 사용하였습니다.
- clone
snapshot 생성을 위해 object cloning (deep, circular) 라이브러리인 clone을 사용했습니다.
- babel-preset-env
jest가 ES6 일부 문법을 이해하지 못해 바벨을 사용하였습니다.
-
ejs
-
express
visualization 웹 서버를 돌리기 위해 express / ejs를 사용하였습니다.
- eslint
코드 스타일은 eslint(airbnb)을 따릅니다.
USAGE
- Singly Linked List
; // SLL 인스턴스 생성const sll = ; sll; // [1]sll; // [1, 2] sllsize; // 2 sll; // 2sll; // 1sll; // undefined sll; // [2]sll; // [1, 2] sll; // 1sll; // 2sll; // undefined // sll.insert(index, value)sll; // [1]sll; // [2, 1]sll; // [2, 4, 1] sll; // Error: index is out of range! // sll.remove(index);sll; // 4// [2, 1]sll; // 2// [1] sll; // Error: index is out of range! sll; // [1, 2]sll; // [1, 2, 3] sll;sll; // [3, 2, 1]
- Doubly Linked List
; // DLL 인스턴스 생성const dll = ; dll; // [1]dll; // [1, 2] dllsize; // 2 dll; // 2dll; // 1dll; // undefined dll; // [2]dll; // [1, 2] dll; // 1dll; // 2dll; // undefined // dll.insert(index, value)dll; // [1]dll; // [2, 1]dll; // [2, 4, 1] dll; // Error: index is out of range! // dll.remove(index);dll; // 4// [2, 1]dll; // 2// [1] dll; // Error: index is out of range! dll; // [1, 2]dll; // [1, 2, 3] dll;dll; // [3, 2, 1]
- Stack
; // 스택 인스턴스 생성const stack = ; stack;stack; stacksize; // 2 stack; // 2stack; // 1stack; // undefined
- Queue
; // 큐 인스턴스 생성const queue = ; queue;queue; queuesize; // 2 queue; // 1queue; // 2queue; // undefined
- Dequeue
; // 덱 인스턴스 생성const dequeue = ; dequeue; // [1]dequeue; // [1, 2]dequeue; // [3, 1, 2] dequeuesize; // 3 dequeue; // 2dequeue; // 3dequeue; // 1dequeue; // undefined
- Heap
; // 힙 인스턴스 생성// new Heap(isMax = true)// 생성자에 인자로 boolean 값을 줄 수 있다.// true 이면 max heap, false 이면 min heap이 생성되고, 기본값은 true 이다.const heap = ; // insert 인자가 number 타입이 아니면 에러가 발생한다.heap; // Error: Invalid value is given! heap; // [4]heap; // [6, 4]heap; // [6, 4, 5]heap; // [10, 6, 5, 4] heapsize; // 4 heap; // 10// [6, 4, 5]heap; // 6// [5, 4]heap; // 5// [4]heap; // 4// []heap; // undefined
- Priority Queue
; // 우선순위 큐 인스턴스 생성const pq = ; // pq.enqueue(priority, value) // priority 가 number 타입이 아니면 에러가 발생한다.pq; // Error: Invalid value is given! pq;// [{3, 'wash your hand'}]pq;// [{3, 'wash your hand'}, {4, 'eat food'}]pq;// [{1, 'find out location of toilet'}, {4, 'eat food'}, {3, 'wash your hand'}] pqsize; // 3 pq; // {priority: 1, value: 'find out location of toilet'}// [{3, 'wash your hand'}, {4, 'eat food'}]pq; // {priority: 3, value: 'wash your hand'}// [{4, 'eat food'}]pq; // {priority: 4, value: 'eat food'}// []pq; // undefined
- Binary Search Tree
; // 이진탐색트리 인스턴스 생성const bst = ; // insert 의 인자가 number 이외의 타입일 경우 에러 발생bst; // Error: Invalid valud is given! bst;// 4bst;// 4// 3bst;// 4// 3 10bst;// 4// 3 10// 100 bst; // truebst; // false bst;// 4// 3 100bst; // Error: given value doesn't exist!!
- Graph
; // 그래프 인스턴스 생성const graph = ; graph;graph;graph; // Error: given value already exists!graph; graph; // 3 graph;graph; // Error: given value doesn't exist!graph;// a// / \// b c graph; // 2 graph;graph; // Error: given value doesn't exist!// a// \// b c graph; // 1 graph;graph; // Error: given value doesn't exist!// a//// b// removeVertex 메소드를 실행하면 해당 vertex에 연결되어 있던 모든 edge들이 제거된다. graph; // 2graph; // 0
- B - Tree
현재 홀수 b-tree 만 지원합니다.
; // B-tree 인스턴스 생성// 생성자 함수의 첫번째 인자로 b-tree의 차수 전달.const btree = 3; // 3차 b-tree 생성4; // Error : invalid value is given! (현재 홀수 b-tree 만 지원합니다.) btree;btree;btree;btree;btree;btree; // Error : given value already exist! btreesize; // 5 // 8// / \// 5 11 13 15 btree; // BTreeNode { values: [12 ,13, 15], children: [], limit: 3 }btree; // false btree;// 11// / \// 5 13 15btree; // Error : given value doesn't exist! btreesize; // 4
TEST
- 테스트 실행
npm run test
SERVER LISTENING
루트 디렉토리에서 npm run start 로 visualization 웹 서버를 3000번 포트에 실행시킬 수 있습니다.
npm run start
웹 뷰 frontend 예시 페이지 : http://ec2-13-209-66-132.ap-northeast-2.compute.amazonaws.com/
LICENSE
MIT