-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.cpp
More file actions
59 lines (46 loc) · 918 Bytes
/
Stack.cpp
File metadata and controls
59 lines (46 loc) · 918 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
49
50
51
52
53
54
55
/**
* @author 13512088 Annisaur Rosi Lutfiana
* @file Stack.cpp
* @class Stack
* @brief Stack generik yang digunakan pada kelas-kelas lain
*/
#include <iostream>
#include <cstdio>
#include "Stack.h"
#include <string>
using namespace std;
template <class T>
int Stack<T>::defaultStackSize = 100;
template <class T>
Stack<T>::Stack():size(defaultStackSize) {
topStack = 0;
data = new T [size];
}
template <class T>
Stack<T>::Stack(int n):size(n) {
topStack = 0;
data = new T [size];
}
template <class T>
Stack<T>::Stack(const Stack& S) {
size = S.size;
topStack = S.topStack;
data = new T [size];
for (int i = 0; i < size; i++) {
data[i] = S.data[i];
}
}
template <class T>
Stack<T>::~Stack() {
delete [] data;
}
template <class T>
void Stack<T>::operator>>(T& x) {
x = data[topStack];
topStack--;
}
template <class T>
void Stack<T>::operator<<(T x) {
topStack++;
data[topStack] = x;
}