3.0.0 โ€ข Published 2 years ago

js-datastructures-ko v3.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

๐Ÿ’ป 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
3.0.0

2 years ago

2.0.0

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago