-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.js
More file actions
49 lines (49 loc) · 1.07 KB
/
map.js
File metadata and controls
49 lines (49 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class map{
constructor(){
this.map = [];
this.size = 0;
}
insert(key,value){
this.map.push([key,value]);
this.size++;
}
erase(key){
for(let i=0;i<this.map.length;i++){
if(this.map[i][0]==key){
this.map.splice(i,1);
this.size--;
return;
}
}
}
find(key){
for(let i=0;i<this.map.length;i++){
if(this.map[i][0]==key){
return this.map[i][1];
}
}
return null;
}
print(){
for(let i=0;i<this.map.length;i++){
console.log(this.map[i][0],this.map[i][1]);
}
}
}
module.exports={
structure:map,
description:"Map",
complexity:{
insert:"O(1)",
erase:"O(n)",
find:"O(n)",
print:"O(n)"
},
methods:{
insert:"Inserts a key-value pair into the map",
erase:"Deletes a key-value pair from the map",
find:"Finds a value in the map",
print:"Prints the map"
},
category:"Map"
};