#include "intstack.h"
#include <iostream>
usingnamespace std;
IntStack print_stack(IntStack* pstack){
for (int i = 0; i < pstack->stack_size; i++){
cout << pstack->st_arr[i] << "\n";
}
}
int IntStack::top(){
stack_size--;
int temp = stack_size;
stack_size++;
return st_arr[temp];
}
int IntStack::size(){
return stack_size;
}
void IntStack::reset(){
//loop through the stack and set each element to NULL
for (int i = 0; i < INITIAL_SIZE; i++){
st_arr[i] = NULL;
}
stack_size = 0;
}
void IntStack::push(int n){
//if stack is full, int cannot be pushed, signal error
if (stack_size == 100){
cerr << "STACK EMPTY\n";
}
//set current element of stack to pushed int then increment index
st_arr[stack_size] = n;
stack_size++;
}
void IntStack::push( int arr[], size_t array_size ){
for (int i = 0; i < array_size; i++){
push(arr[i]);
}
}
int IntStack::pop(){
//if stack is empty, int cannot be set to null, signal error
if (stack_size == 0){
cerr << "STACK EMPTY\n";
}
else
//decrement to previous stack index then set it to NULL
--stack_size;
int temp = st_arr[stack_size];
st_arr[stack_size] = NULL;
return temp;
}
void IntStack::pop( int a[], size_t n ){
stack_size--;
for (int idx = 0; idx < n; idx++){
a[idx] = st_arr[stack_size];
st_arr[stack_size] = NULL;
if(stack_size>0)stack_size--;
}
//for (i = 0; st_arr[i] != NULL; i++);
//cout << "after popping, i is " << i << "\n"; //DB
}
void IntStack::double_capacity(){
int* new_mem = allocate(capacity * 2);
for (int i = 0; i < stack_size; i++){
new_mem[i] = st_arr[i];
}
deallocate(st_arr);
st_arr = new_mem;
capacity *= 2;
}
int* allocate(int num){
int* new_mem = newint[num];
return new_mem;
}
void deallocate(int* old){
delete[] old;
}
bool IntStack::is_full(){
if(stack_size == 100)
returntrue;
elsereturnfalse;
}
bool IntStack::is_empty(){
if(stack_size != 0)
returnfalse;
elsereturntrue;
}
Does it have something to do with an include directive?