feat: ohhhhhh babe
This commit is contained in:
parent
37aa7f0066
commit
b35341ac1a
7 changed files with 31 additions and 13 deletions
|
|
@ -17,9 +17,8 @@ module.exports = {
|
|||
"CompareBinaryTrees",
|
||||
"DFSOnBST",
|
||||
"Trie",
|
||||
"DFSGraphList",
|
||||
"DFSGraphMatrix",
|
||||
"BFSGraphList",
|
||||
"BFSGraphMatrix",
|
||||
"Map",
|
||||
],
|
||||
}
|
||||
|
|
|
|||
|
|
@ -251,14 +251,14 @@ module.exports = {
|
|||
BTBFS: {
|
||||
type: "fn",
|
||||
fn: "bfs",
|
||||
args: "head: BinaryNode<number>",
|
||||
return: "number[]",
|
||||
args: "head: BinaryNode<number>, needle: number",
|
||||
return: "boolean",
|
||||
},
|
||||
|
||||
CompareBinaryTrees: {
|
||||
type: "fn",
|
||||
fn: "compare",
|
||||
args: "a: BinaryNode<number>, b: BinaryNode<number>",
|
||||
args: "a: BinaryNode<number> | null, b: BinaryNode<number> | null",
|
||||
return: "boolean",
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ test("post order", function () {
|
|||
5,
|
||||
15,
|
||||
10,
|
||||
15,
|
||||
29,
|
||||
45,
|
||||
30,
|
||||
100,
|
||||
50,
|
||||
20,
|
||||
]);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import compare from "@code/CompareBinaryTrees";
|
||||
import { tree, tree2 } from "./tree";
|
||||
|
||||
test("bt bfs", function () {
|
||||
test("Compare Binary Trees", function () {
|
||||
expect(compare(tree, tree)).toEqual(true);
|
||||
expect(compare(tree, tree2)).toEqual(false);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,16 +1,33 @@
|
|||
export function test_list(list: List<number>): void {
|
||||
list.add(5);
|
||||
list.add(7);
|
||||
list.add(9);
|
||||
list.append(5);
|
||||
list.append(7);
|
||||
list.append(9);
|
||||
|
||||
// @ts-ignore
|
||||
console.log(list.data);
|
||||
|
||||
expect(list.get(2)).toEqual(9);
|
||||
expect(list.removeAt(1)).toEqual(7);
|
||||
// @ts-ignore
|
||||
console.log(list.data);
|
||||
expect(list.length).toEqual(2);
|
||||
|
||||
list.add(11);
|
||||
list.append(11);
|
||||
// @ts-ignore
|
||||
console.log(list.data);
|
||||
expect(list.removeAt(1)).toEqual(9);
|
||||
expect(list.remove(9)).toEqual(undefined);
|
||||
expect(list.removeAt(0)).toEqual(5);
|
||||
expect(list.removeAt(0)).toEqual(11);
|
||||
expect(list.length).toEqual(0);
|
||||
|
||||
list.prepend(5);
|
||||
list.prepend(7);
|
||||
list.prepend(9);
|
||||
|
||||
expect(list.get(2)).toEqual(5);
|
||||
expect(list.get(0)).toEqual(9);
|
||||
expect(list.remove(9)).toEqual(9);
|
||||
expect(list.length).toEqual(2);
|
||||
expect(list.get(0)).toEqual(7);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ list2[6] = [
|
|||
// >(2) --> (3) <----(6)
|
||||
export const matrix2: WeightedAdjacencyMatrix = [
|
||||
[0, 3, 1, 0, 0, 0, 0], // 0
|
||||
[0, 0, 0, 1, 0, 0, 0],
|
||||
[0, 0, 0, 0, 1, 0, 0],
|
||||
[0, 0, 7, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 0, 0, 0],
|
||||
[0, 1, 0, 5, 0, 2, 0],
|
||||
|
|
|
|||
4
src/global.d.ts
vendored
4
src/global.d.ts
vendored
|
|
@ -8,7 +8,9 @@ declare interface List<T> {
|
|||
removeAt(index: number): T | undefined;
|
||||
remove(item: T): T | undefined;
|
||||
get(index: number): T | undefined;
|
||||
add(item: T): void;
|
||||
prepend(item: T): void;
|
||||
append(item: T): void;
|
||||
insertAt(item: T, idx: number): void;
|
||||
}
|
||||
|
||||
declare type CompleteGraphEdge = { from: number; to: number; weight: number };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue