Storing data in a linear collection...
int[] arr = {1, 2, 3, 4};
Data structures where elements are linked using pointers...
Bubble Sort, Merge Sort, Quick Sort...
A stack is a linear data structure that follows Last In First Out (LIFO) principle...
class Stack {
constructor() {
this.stack = [];
}
push(value) {
this.stack.push(value);
}
pop() {
return this.stack.pop();
}
}
A queue is a linear data structure that follows First In First Out (FIFO) principle...
class Queue {
constructor() {
this.queue = [];
}
enqueue(value) {
this.queue.push(value);
}
dequeue() {
return this.queue.shift();
}
}
A binary tree where each node has at most two children, and the left child is less than the parent node...
class Node {
constructor(value) {
this.value = value;
this.left = null;
this.right = null;
}
}
function insert(root, value) {
if (!root) {
return new Node(value);
}
if (value < root.value) {
root.left = insert(root.left, value);
} else {
root.right = insert(root.right, value);
}
return root;
}