diff --git a/src/app/algorithms/page.tsx b/src/app/algorithms/page.tsx deleted file mode 100644 index 623aad5..0000000 --- a/src/app/algorithms/page.tsx +++ /dev/null @@ -1,31 +0,0 @@ -import Link from "next/link"; -import BubbleSort from "./bubblesort/page"; - -const Algorithms = () => { - return ( - <> -
-
- - The Parth Algorithms -
-
- - - Bubble sort - - - Insertion sort - - - Quick sort (WIP) - -
-
- - - ) - -} - -export default Algorithms; \ No newline at end of file diff --git a/src/app/algorithms/bubblesort/bubbleSort.ts b/src/app/dsa/bubblesort/bubbleSort.ts similarity index 100% rename from src/app/algorithms/bubblesort/bubbleSort.ts rename to src/app/dsa/bubblesort/bubbleSort.ts diff --git a/src/app/algorithms/bubblesort/page.tsx b/src/app/dsa/bubblesort/page.tsx similarity index 100% rename from src/app/algorithms/bubblesort/page.tsx rename to src/app/dsa/bubblesort/page.tsx diff --git a/src/app/algorithms/insertionsort/insertionSort.ts b/src/app/dsa/insertionsort/insertionSort.ts similarity index 100% rename from src/app/algorithms/insertionsort/insertionSort.ts rename to src/app/dsa/insertionsort/insertionSort.ts diff --git a/src/app/algorithms/insertionsort/page.tsx b/src/app/dsa/insertionsort/page.tsx similarity index 100% rename from src/app/algorithms/insertionsort/page.tsx rename to src/app/dsa/insertionsort/page.tsx diff --git a/src/app/dsa/page.tsx b/src/app/dsa/page.tsx new file mode 100644 index 0000000..1007e09 --- /dev/null +++ b/src/app/dsa/page.tsx @@ -0,0 +1,42 @@ +import Link from "next/link"; +import BubbleSort from "./bubblesort/page"; + +const Algorithms = () => { + return ( + <> +
+
+ + The Parth Structures and Algorithms +
+ +
+
+ Algorithms +
+
+ + + Bubble sort + + + Insertion sort + + + Quick sort (WIP) + + +
+ +
+ Data Structures +
+
+
+ + + ) + +} + +export default Algorithms; \ No newline at end of file diff --git a/src/app/algorithms/quicksort/page.tsx b/src/app/dsa/quicksort/page.tsx similarity index 100% rename from src/app/algorithms/quicksort/page.tsx rename to src/app/dsa/quicksort/page.tsx diff --git a/src/app/algorithms/quicksort/quicksort.ts b/src/app/dsa/quicksort/quicksort.ts similarity index 100% rename from src/app/algorithms/quicksort/quicksort.ts rename to src/app/dsa/quicksort/quicksort.ts diff --git a/src/app/dsa/tree/tree.ts b/src/app/dsa/tree/tree.ts new file mode 100644 index 0000000..bdbea40 --- /dev/null +++ b/src/app/dsa/tree/tree.ts @@ -0,0 +1,71 @@ +import { root } from "postcss" + +type Node = { + value: number, + leftNode?: Node, + rightNode?: Node, +} + +// type CreateProps = { +// root?: Node +// value: number +// leftNode: Node +// rightNode: Node +// } + +// takes a value and a tree (root) and returns a new tree (root) +const insertNode = (value: number, root: Node): Node => { + if (value < root.value) { + if (root.leftNode) insertNode(value, root.leftNode) + else root.leftNode = { value } + } + else { + if (root.rightNode) insertNode(value, root.rightNode) + else root.rightNode = { value } + } + + return root + + +} +const readTree = (root: Node, callback: Function) => { + callback('parent:', root.value) + if (root.leftNode) callback('left: ', root.leftNode.value); + if (root.rightNode) callback('right: ', root.rightNode.value); + if (root.leftNode) readTree(root.leftNode, callback); + if (root.rightNode) readTree(root.rightNode, callback); +} + + + + + +const startArr = [1, 2, 5, 6, 8, 3, 9, 4, 7, 10] + +const startNode: Node = { + value: 5, + leftNode: { + value: 3, + leftNode: { + value: 2 + }, + // rightNode: { + // value: 4 + // } + }, + rightNode: { + value: 7, + leftNode: { + value: 6, + } + } + +} + +insertNode(4, startNode); +readTree(startNode, console.log); + + + + + diff --git a/src/app/page.tsx b/src/app/page.tsx index 81f872f..1ca0dda 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -3,7 +3,7 @@ import { redirect } from "next/navigation"; const Home = () => { - redirect('/algorithms') + redirect('/dsa') }