-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatastructuresCPP.cpp
More file actions
65 lines (48 loc) · 1.41 KB
/
Copy pathdatastructuresCPP.cpp
File metadata and controls
65 lines (48 loc) · 1.41 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
57
58
59
60
61
62
63
64
65
#include <iostream>
using namespace std;
// Here we insert declarations of the classes we want to make use of and global constants:
class stack;
class graph_node;
class graph;
const int MAX_SIZE = 200000;
// ---------------------------------------------------------------------
/* STACK
* This is an adhoc implementation of the stack. It allocates an array of size 'MAX_SIZE', as is defined above. This array is an auxilary array
* in which data is stored. However, any data above the current size is considered 'trash data' and will be written over if insertion() is called.
* For example, if we have aux = [1,2...], size = 2. Now we call pop() -> aux = [1,2..], but size = 1, meaning that the 2 on index 1 is 'trashdata'.
* If we now call insertion(3), we get aux = [1,3...], and pop() --> returns 3, and in aux [1,3..], the 3 is now considered to be 'trash data'.
*/
class stack{
int max_size;
int size = 0;
int aux_array[MAX_SIZE];
public:
void insertion(int n) {
aux_array[size] = n;
size += 1;
}
int pop(){
size -= 1;
return aux_array[size];
}
};
class graph_node {
};
class graph {
private:
int max_size;
int size = 0;
int aux_array[];
public:
void set_max_size(int n) {
max_size = n;
aux_array[n];
}
};
int main()
{
std::cout << "Hello World!\n";
stack s;
s.insertion(4);
std::cout << s.pop();
}