summaryrefslogtreecommitdiff
path: root/1_anno/Programmazione_2/data_structures/stack_w_array.cc
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-02-06 19:56:36 +0100
committerSanto Cariotti <santo@dcariotti.me>2021-02-06 19:56:36 +0100
commitd2edbc38cac8da52f58c5cd3da6c0c625fa05736 (patch)
treea51e9a4e56fc9d4c7c9e37576dceedca3a0c72b4 /1_anno/Programmazione_2/data_structures/stack_w_array.cc
parent98f34040820dc3a964b7be59a698323e8cc6c8a3 (diff)
conf: rename
Diffstat (limited to '1_anno/Programmazione_2/data_structures/stack_w_array.cc')
-rw-r--r--1_anno/Programmazione_2/data_structures/stack_w_array.cc50
1 files changed, 0 insertions, 50 deletions
diff --git a/1_anno/Programmazione_2/data_structures/stack_w_array.cc b/1_anno/Programmazione_2/data_structures/stack_w_array.cc
deleted file mode 100644
index c20db90..0000000
--- a/1_anno/Programmazione_2/data_structures/stack_w_array.cc
+++ /dev/null
@@ -1,50 +0,0 @@
-#include<iostream>
-
-using namespace std;
-
-template<class H>
-class stack {
-public:
- stack(int n) : _size{n}, _top{-1} {
- _arr = new H[n];
- }
- ~stack() {
- delete _arr;
- }
- bool is_empty() {
- return _top == -1;
- }
- bool is_full() {
- return _top == _size-1;
- }
- stack<H>* push(H x) {
- if(!is_full()) {
- _arr[++_top] = x;
- }
- return this;
- }
- H pop() {
- if(is_empty())
- return -1;
- _top--;
- return _arr[_top+1];
- }
-private:
- int _size;
- H* _arr;
- short _top;
-};
-
-int main() {
- stack<int>* s = new stack<int>{7};
-
- s->push(15)->push(6)->push(2)->push(9)->push(17)->push(3);
- cout << s->pop() << '\n';
- s->push(18)->push(19)->push(12);
-
- for(int i = 0; i < 7; ++i)
- cout << s->pop() << ' ';
-
- delete s;
- return 0;
-}