1
0
Fork 0
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.
uni-m.cds-adv-prog/Stack/Stack.hh

55 lines
912 B
C++
Raw Normal View History

2019-12-12 17:17:46 +01:00
//Stack.h
#ifndef STACK_H
#define STACK_H
2019-12-12 15:56:38 +01:00
const int DELTA = 5 ; // default growing size
2019-12-12 17:17:46 +01:00
class Stack {
// Interface
public:
2019-12-12 15:56:38 +01:00
Stack() { init( DELTA ); }
Stack( int in_size ) { init(in_size); }
2019-12-12 16:56:16 +01:00
Stack(const Stack& other) {
// Use init to set all vars naturally
init( other.bufsize ) ;
if ( s == other.s )
{
std::cout << "sAmE" << std::endl;
}
// Then update the count as this is dependant on the copied Stack
count = other.count ;
// Copy elements
for ( int i=0 ; i < bufsize ; i++ ) {
s[i] = other.s[i] ;
}
}
2019-12-12 15:56:38 +01:00
~Stack() {
delete[] s;
}
2019-12-12 17:17:46 +01:00
int nitems() { return count ; }
2019-12-12 15:56:38 +01:00
bool full() { return (count==bufsize) ; }
2019-12-12 17:17:46 +01:00
bool empty() { return (count==0) ; }
void push( double c );
double pop();
void inspect();
2019-12-12 15:56:38 +01:00
void grow( int delta );
2019-12-12 17:17:46 +01:00
// Implementation
private:
2019-12-12 15:56:38 +01:00
void init( int in_size );
double* s ;
2019-12-12 17:17:46 +01:00
int count ;
2019-12-12 15:56:38 +01:00
int bufsize ;
2019-12-12 17:17:46 +01:00
};
#endif