목록DataStructure (6)
Muscardinus
class Graph { constructor() { this.numberOfNodes = 0; this.adjacentList = { }; } addVertex(node) { if (!this.adjacentList[node]) { this.adjacentList[node] = []; this.numberOfNodes++; } } addEdge(node1, node2) { //undirected Graph if (!(this.adjacentList[node1] && this.adjacentList[node2])) return null; this.adjacentList[node1].push(node2); this.adjacentList[node2].push(node1); } showConnections(..
이진탐색트리 시뮬레이션 연습 사이트 visualgo.net/en/bst class Node { constructor(value){ this.left = null; this.right = null; this.value = value; } } class BinarySearchTree { constructor(){ this.root = null; } insert(value){ const newNode = new Node(value); if (!this.root) this.root = newNode; else { let currentNode = this.root; while(1) { if (value < currentNode.value) { if (!currentNode.left) { currentNode.le..
Linked List Method class Node { constructor(value) { this.value = value; this.next = null; } } class Queue { constructor() { this.first = null; this.last = null; this.length = 0; } peek() { return this.fist; } enqueue(value) { const newNode = new Node(value); if (!this.length) { this.first = this.last = newNode; } else { this.last.next = newNode; this.last = newNode; } this.length++; return this..
Linked List Method class Node { constructor(value) { this.value = value; this.next = null; } } class Stack { constructor() { this.top = null; this.bottom = null; this.length = 0; } peek() { return this.top; } push(value) { const newNode = new Node(value); if (!this.length) { this.top = newNode; this.bottom = newNode; } else { this.top.next = newNode; this.top = newNode; } this.length++; return t..
class DoublyLinkedList { constructor(value) { this.head = { value: value, next: null, prev: null, }; this.tail = this.head; this.length = 1; } append(value) { const newNode = { value: value, next: null, prev: null, } newNode.prev = this.tail; this.tail.next = newNode; this.tail = newNode; this.length++; return this; } prepend(value) { const newNode = { value: value, next: null, prev: null, } new..
class LinkedList { constructor(value) { this.head = { value: value, next: null }; this.tail = this.head; this.length = 1; } append(value) { const newNode = { value: value, next: null } console.log(newNode) this.tail.next = newNode; this.tail = newNode; this.length++; return this; } prepend(value) { const newNode = { value: value, next: null } newNode.next = this.head; this.head = newNode; this.l..