forked from BitSails/adts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackV.cpp
More file actions
43 lines (33 loc) · 693 Bytes
/
Copy pathStackV.cpp
File metadata and controls
43 lines (33 loc) · 693 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
#include "StackV.h"
#include <iostream>
#include <stdexcept>//used to be able to "throw" exceptions
using namespace std;
void Stack::push(int val)
{
data.push_back(val);
}
void Stack::pop()
{
if (data.empty()==true)//if the location is invalid
throw out_of_range("Stack::pop()");//throw an "out_of_range" exception
else
data.pop_back();
}
void Stack::clear()
{
while (size()!=0)
{
data.clear();
}
}
int Stack::size()
{
return data.size();
}
int Stack::top()
{
if (data.empty()==true)//if the location is invalid
throw out_of_range("List::top()");//throw an "out_of_range" exception
else
return data.back();
}