-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector.js
More file actions
56 lines (54 loc) · 1.16 KB
/
vector.js
File metadata and controls
56 lines (54 loc) · 1.16 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
50
51
52
53
54
55
56
class vector{
data=[];
constructor(){
this.data=[];
}
push_back(data){
this.data.push(data);
}
pop_back(){
if(this.data.length>0)
this.data.pop();
else throw "Empty Vector";
}
print(){
for(let i=0;i<this.data.length;i++){
console.log(this.data[i]);
}
}
sort(){
this.data.sort();
}
size(){
return this.data.length;
}
at(index){
return this.data[index];
}
erase(){
this.data=[];
}
}
module.exports={
structure:vector,
description:"Vector",
complexity:{
push_back:"O(1)",
pop_back:"O(1)",
print:"O(n)",
sort:"O(nlogn)",
size:"O(1)",
at:"O(1)",
erase:"O(1)"
},
methods:{
push_back:"Adds an element to the end of the vector",
pop_back:"Removes the last element from the vector",
print:"Prints the vector",
sort:"Sorts the vector",
size:"Returns the size of the vector",
at:"Returns the element at the given index",
erase:"Erases the vector"
},
category:"Vector"
};