const int maxstack = 10;
enum Error_code{success,overflow,underflow};
typedef char stack_entry;
class stack{
public:
stack();
Error_code push(const stack_entry&item);
Error_code copy_stack(stack&dest,stack&source);
Error_code recover(stack&dest,stack&source);
private:
stack_entry dest[maxstack];
stack_entry source[maxstack];
int count;
};
Error_code stack::push(const stack_entry&item);
{
Error_code outcome = success;
if(count >= maxstack)
outcome = overflow;
else source[count++] = item;
return outcome;
}
Error_code stack::copy_stack(stack&dest,stack&source);
{
int n;
Error_code outcome = success;
for(n=0;n<=10;n++)
if(count==0)
outcome = underflow;
else
dest[n] = source[count--];
count--;
return outcome;
};
Error_code stack::recover(stack&dest,stack&source)
{
int n;
Error_code outcome = success;
for(n=0;n<=10;n++)
if(count==0)
outcome = underflow;
else
source[n] = dest[count--];
count--;
return outcome;
};
enum Error_code{success,overflow,underflow};
typedef char stack_entry;
class stack{
public:
stack();
Error_code push(const stack_entry&item);
Error_code copy_stack(stack&dest,stack&source);
Error_code recover(stack&dest,stack&source);
private:
stack_entry dest[maxstack];
stack_entry source[maxstack];
int count;
};
Error_code stack::push(const stack_entry&item);
{
Error_code outcome = success;
if(count >= maxstack)
outcome = overflow;
else source[count++] = item;
return outcome;
}
Error_code stack::copy_stack(stack&dest,stack&source);
{
int n;
Error_code outcome = success;
for(n=0;n<=10;n++)
if(count==0)
outcome = underflow;
else
dest[n] = source[count--];
count--;
return outcome;
};
Error_code stack::recover(stack&dest,stack&source)
{
int n;
Error_code outcome = success;
for(n=0;n<=10;n++)
if(count==0)
outcome = underflow;
else
source[n] = dest[count--];
count--;
return outcome;
};