This repository has been archived on 2021-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
2019-12-12 17:17:46 +01:00
|
|
|
//Stack.cc
|
2019-11-14 20:45:16 +01:00
|
|
|
#include <iostream>
|
2019-12-12 17:17:46 +01:00
|
|
|
#include "Stack.hh"
|
2019-11-14 20:45:16 +01:00
|
|
|
|
2019-12-12 17:17:46 +01:00
|
|
|
void Stack::push(double c) {
|
|
|
|
if (full()) {
|
|
|
|
std::cout << "Stack::push() Error: stack is full" << std::endl ;
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
s[count++] = c ;
|
|
|
|
}
|
2019-11-14 20:45:16 +01:00
|
|
|
|
2019-12-12 17:17:46 +01:00
|
|
|
double Stack::pop() {
|
|
|
|
if (empty()) {
|
|
|
|
std::cout << "Stack::pop() Error: stack is empty" << std::endl ;
|
|
|
|
return 0 ;
|
|
|
|
}
|
|
|
|
return s[--count] ;
|
|
|
|
}
|
2019-11-14 20:45:16 +01:00
|
|
|
|
2019-12-12 17:17:46 +01:00
|
|
|
void Stack::inspect() {
|
|
|
|
for ( int i = nitems() - 1; i >= 0; i-- )
|
|
|
|
{
|
|
|
|
std::cout << i << ": " << s[i] << std::endl;
|
|
|
|
}
|
2019-11-14 20:45:16 +01:00
|
|
|
}
|