3.0.0 โข Published 2 years ago
js-datastructures-ko v3.0.0
๐ป js-datastructures-ko
- npm ๋ฐฐํฌ ๊ฒฝํ๊ณผ ์ฌ๋ฌ๊ฐ์ง ์๋ฃ ๊ตฌ์กฐ๋ฅผ ์๋ฐ์คํฌ๋ฆฝํธ๋ก ๊ตฌํํ๊ธฐ ์ํด ๋ง๋ ์ ์ฅ์์ ๋๋ค. ๐
- It is a repository created to implement npm deployment experience and various data structures in JavaScript. ๐
๐ ํจํค์ง ์ค์น(Package Installation)
npm install js-datastructures-ko
yarn add js-datastructures-ko
๐ ํจํค์ง ์ฌ์ฉ ๊ฐ์ด๋(Package Usage Guide)
1. ์คํ(Stack)
- ์ปดํจํฐ์ ๊ธฐ๋ณธ์ ์ธ ์๋ฃ ๊ตฌ์กฐ์ค ํ๊ฐ์ง๋ก, ์
์ถ๋ ฅ ๋ฐฉ์์
ํ์ ์ ์ถ(LIFO:Last In, First Out)
๋ฐฉ์์ธ ์๋ฃ ๊ตฌ์กฐ์ด๋ค. - It is one of the basic data structures of computers, and the input/output method is a
Last in, First Out (FIFO)
method.
const { Stack } = requires('js-datastructures-ko');
const stack = new Stack();
stack.push(1);
stack.push(2);
stack.push(3);
stack.push(4);
console.log(stack.pop()); // 4
console.log(stack); // Stack { arr: [ 1, 2, 3 ], length: 3 }
console.log(stack.top()); // 3
console.log(stack.bottom()); // 1
stack.print() // 1 2 3
2. ํ(Queue)
- ์ปดํจํฐ์ ๊ธฐ๋ณธ์ ์ธ ์๋ฃ ๊ตฌ์กฐ์ค ํ๊ฐ์ง๋ก, ์
์ถ๋ ฅ ๋ฐฉ์์
์ ์ ์ ์ถ(FIFO:First In, First Out)
๋ฐฉ์์ธ ์๋ฃ ๊ตฌ์กฐ์ด๋ค. - It is one of the basic data structures of computers, and the input/output method is a
First in, First Out (FIFO)
method.
const { Queue } = require("js-datastructures-ko");
const queue = new Queue();
queue.enqueue(1);
queue.enqueue(2);
queue.enqueue(3);
queue.enqueue(4);
console.log(queue.dequeue()); // 1
console.log(queue); // Queue { arr: [ 2, 3, 4 ], length: 3 }
console.log(queue.top()); // 4
console.log(queue.bottom()); // 2
queue.print() // 2 3 4
3. ์ฐ๊ฒฐ๋ฆฌ์คํธ(Linked list)
- ์๋ฃ๊ตฌ์กฐ์ ๊ฐ ๋ถ๋ถ์ธ
๋ ธ๋๋ค์ด ์ฐ๊ฒฐ๋์ด ์๋ ๋ฐฉ์
์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ์ ์ฅํ๋ ์๋ฃ๊ตฌ์กฐ์ด๋ค. - It is a data structure that stores data in a way that nodes, which are each part of the data structure, are connected.
const { LinkedList } = require("js-datastructures-ko");
const linkedList = new LinkedList();
linkedList.prepend(1);
linkedList.append(2);
linkedList.append(4);
linkedList.insertAt(3, 2);
/*
LinkedList {
length: 4,
head: Node { data: 1, next: Node { data: 2, next: [Node] } }
}
*/
console.log(linkedList);
console.log(linkedList.search(2)); // 3
linkedList.removeAt(0);
linkedList.print(); // 2 3 4
4. ํด์ ๋งต(HashMap)
- Java์์๋ HashMap๊ณผ ์ ์ฌํ๊ฒ ์๋ฐ์คํฌ๋ฆฝํธ๋ก ๊ตฌํ
- It's implemented in JavaScript similar to HashMap in Java.
- Map ์ธํฐํ์ด์ค์ ํ ์ข
๋ฅ,
key-value
ํํ๋ก ๋ฐ์ดํฐ๋ฅผ ๋ฌถ์ด entry๋ก ์ ์ฅํ๋ ํํ์ด๋ค. - It is a type of Map interface, a form of key-value, in which data is grouped and stored as entry.
const { HashMap } = require("js-datastructures-ko");
const hashMap = new HashMap();
hashMap.put("hi", 1);
hashMap.put("bye", 2);
hashMap.put(1, 3);
hashMap.remove("hi");
console.log(hashMap); // HashMap { map: { '1': 3, bye: 2 } }
console.log(hashMap.get(1)); // 3
console.log(hashMap.containsKey("hi")); // false
console.log(hashMap.containsValue(2)); // true
console.log(hashMap.keys()); // [ '1', 'bye' ]
console.log(hashMap.values()); // [ 3, 2 ]
const clone = hashMap.clone();
clone.put("hahaha", "hahaha");
console.log(hashMap); // HashMap { map: { '1': 3, bye: 2 } }
console.log(clone); // HashMap { map: { '1': 3, bye: 2, hahaha: 'hahaha' } }
hashMap.clear();
console.log(hashMap.isEmpty()); // true