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.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); }
|
|
|
|
~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
|