Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8bed54e

Browse files
Exportable data structures
All data structures will be exported going forward. Array and Hash Table implementations were corrected.
1 parent 6fc66ea commit 8bed54e

File tree

2 files changed

+47
-37
lines changed

2 files changed

+47
-37
lines changed

‎Data-Structures/Arrays/Implementation.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
type NumIndexedObject = { [index: number]: any };
44

5-
class MyArray<T> {
5+
exportclass MyArray<T> {
66

77
public length: number;
88
private data: NumIndexedObject;
@@ -83,39 +83,43 @@ class MyArray<T> {
8383

8484

8585

86-
let helloArray = new MyArray<string>();
86+
//---------------------------------------------------------------------
87+
// ---------- MAIN PROGRAM ----------
88+
//---------------------------------------------------------------------
89+
if (import.meta.main) {
8790

88-
helloArray.push('Hello'); // O(1)
89-
helloArray.push('world');
90-
console.log(helloArray);
91+
let helloArray = new MyArray<string>();
9192

92-
helloArray.pop(); // O(1)
93-
console.log(helloArray);
93+
helloArray.push('Hello'); // O(1)
94+
helloArray.push('world');
95+
console.log(helloArray);
9496

95-
helloArray.push('Deno');
96-
helloArray.push('!');
97-
console.log(helloArray);
97+
helloArray.pop(); // O(1)
98+
console.log(helloArray);
9899

99-
console.log('At index 2:', helloArray.get(2));
100+
helloArray.push('Deno');
101+
helloArray.push('!');
102+
console.log(helloArray);
100103

101-
// -------------------------------------------
104+
console.log('At index 2:',helloArray.get(2));
102105

103-
letsokka=newMyArray<string>();
106+
// -------------------------------------------
104107

105-
sokka.push('s');
106-
sokka.push('o');
107-
sokka.push('c');
108-
sokka.push('k');
109-
sokka.push('a');
110-
console.log(sokka);
108+
let sokka = new MyArray<string>();
111109

112-
console.log('Element deleted:', sokka.deleteIndex(2)); // O(n)
113-
console.log(sokka);
114-
115-
sokka.insertItemAtIndex(2, 'k'); // O(n)
116-
console.log(sokka);
110+
sokka.push('s');
111+
sokka.push('o');
112+
sokka.push('c');
113+
sokka.push('k');
114+
sokka.push('a');
115+
console.log(sokka);
117116

117+
console.log('Element deleted:', sokka.deleteIndex(2)); // O(n)
118+
console.log(sokka);
118119

120+
sokka.insertItemAtIndex(2, 'k'); // O(n)
121+
console.log(sokka);
122+
}
119123

120124
// --------------------------- Terminal Output: ---------------------------
121125
// MyArray { length: 2, data: { 0: "Hello", 1: "world" }}

‎Data-Structures/Hash-Tables/Implementation.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: deno run Data-Structures/Hash-Tables/Implementation.ts
22

3-
class HashTable {
3+
exportclass HashTable {
44
private size: number;
55
private data: Array<Array<any>>;
66

@@ -80,21 +80,27 @@ class HashTable {
8080
}
8181

8282
public testHashFunction() {
83-
console.log(hashTable._hash('grapes'));
84-
console.log(hashTable._hash('grapess'));
85-
console.log(hashTable._hash('grapes'));
83+
console.log(this._hash('grapes'));
84+
console.log(this._hash('grapess'));
85+
console.log(this._hash('grapes'));
8686
}
8787
}
8888

89-
const hashTable = new HashTable(16);
90-
// hashTable.testHashFunction();
89+
//---------------------------------------------------------------------
90+
// ---------- MAIN PROGRAM ----------
91+
//---------------------------------------------------------------------
92+
if (import.meta.main) {
9193

92-
hashTable.set('grapes', 27);
93-
hashTable.set('apples', 6);
94-
hashTable.set('tangerines', 12);
94+
const hashTable = new HashTable(16);
95+
// hashTable.testHashFunction();
9596

96-
console.log('apples:', hashTable.get('apples'));
97-
console.log('grapes:', hashTable.get('grapes'));
97+
hashTable.set('grapes', 27); // Θ(1)
98+
hashTable.set('apples', 6);
99+
hashTable.set('tangerines', 12);
98100

99-
console.log(hashTable.keys());
100-
console.log(hashTable.values());
101+
console.log('apples:', hashTable.get('apples'));
102+
console.log('grapes:', hashTable.get('grapes'));
103+
104+
console.log(hashTable.keys());
105+
console.log(hashTable.values());
106+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /