This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
LAB 3 | |
Objectives 3 | |
Binary tree's are data structures that have a hierarchical form and represent trees | |
whose elements have a maximum number of two children. These children are called the | |
left and the right child. The binary tree root represents the top node. | |
A node that has at least one child is considered a parent of its child. | |
A leaf is a node that has no children. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Doubly linked lists | |
Doubly linked list is a type of data structure that is made up of so called objects | |
that are created using self referential structures. Each of these nodes contain three | |
attributes, namely the value and the reference to the next list object and the reference | |
to the previous list object. | |
In this exercise you will create a doubly linked list, which exposes 4 methods: | |
push_back(): add values to the end of the list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <list> | |
using namespace std; | |
class Hash { | |
int BUCKET; | |
list<int> *table; // pointer to an array containing buckets | |
public: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { defaultMemoize } from "./memoizedSelector"; | |
import { slowFunction } from "./slowFunction"; | |
// run slowFunction without memoization | |
console.log("First call of slowFunction(2)"); | |
let pre = new Date(); | |
slowFunction(2); | |
console.log("It takes" + ((new Date()).valueOf() - pre.valueOf())/1000 + "seconds \n"); | |
console.log("Second call of slowFunction(2)"); | |
pre = new Date(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function slowFunction(val: number): number { | |
const pre = new Date(); | |
while (true) { | |
const now = new Date(); | |
if (now.valueOf() - pre.valueOf() > 2000) { | |
break; | |
} | |
} | |
return val; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type AnyFn = (...args: any[]) => any; | |
export type ComparatorFn = (a: any, b: any) => boolean; | |
export type MemoizedProjection = { | |
memoized: AnyFn; | |
reset: () => void; | |
setResult: (result?: any) => void; | |
}; |