-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset.js
More file actions
48 lines (48 loc) · 963 Bytes
/
set.js
File metadata and controls
48 lines (48 loc) · 963 Bytes
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
class set{
constructor(){
this.set=[];
}
add(data){
if(!this.set.includes(data)){
this.set.push(data);
}
}
pop(){
this.set.pop();
}
print(){
for(let i=0;i<this.set.length;i++){
console.log(this.set[i]);
}
}
sort(){
this.set.sort();
}
size(){
return this.set.length;
}
at(index){
return this.set[index];
}
}
module.exports={
structure:set,
description:"Set",
complexity:{
add:"O(n)",
pop:"O(1)",
print:"O(n)",
sort:"O(nlogn)",
size:"O(1)",
at:"O(1)"
},
methods:{
add:"Adds an element to the set",
pop:"Removes the last element from the set",
print:"Prints the set",
sort:"Sorts the set",
size:"Returns the size of the set",
at:"Returns the element at the given index"
},
category:"Set"
};