Make a function "reverse" in your stack class that reverses the whole stack...

Problem: Make a function "reverse" in your stack class that reverses the whole stack. In your driver file (main.cpp), make integer stack, push some values in it, call the reverse function to reverse the stack, and then print the stack. header and .cpp files are given below. Need to use this.

 

/*StackType.h */

#ifndef STACKTYPE_H_INCLUDED

#define STACKTYPE_H_INCLUDED

#include <iostream>

using namespace std;

const int MAX_ITEMS = 5;

class FullStack

// Exception class thrown

// by Push when stack is full.

{

  void printExceptionMsg(){

    cout<<"Stack is full"<<endl;

  }

};

class EmptyStack

// Exception class thrown

// by Pop and Top when stack is empty.

{

private:

  string reason;

public:

  EmptyStack(string reason){

    this->reason = reason;

  }

  //int x = 5;

  void printExceptionMsg(){

    cout<<"Empty stack exception thrown from "<<reason<<endl;

  }

};

template <class ItemType>

class StackType

{

public:

  StackType();

  bool IsFull();

  bool IsEmpty();

  void Push(ItemType);

  void Pop();

  ItemType Top();

private:

  int top;

  ItemType items[MAX_ITEMS];

};

#include "StackType.tpp"

#endif // STACKTYPE_H_INCLUDED

 

/*StackType.tpp */

#include "StackType.h"

template <class ItemType>

StackType<ItemType>::StackType()

{

  //items = new ItemType[MAX_ITEMS];

  top = -1;

}

template <class ItemType>

bool StackType<ItemType>::IsEmpty()

{

  return (top == -1);

}

template <class ItemType>

bool StackType<ItemType>::IsFull()

{

  return (top == MAX_ITEMS-1);

}

template <class ItemType>

void StackType<ItemType>::Push(ItemType newItem)

{

  if(IsFull())

    throw FullStack();

  top++;

  items[top] = newItem;

}

template <class ItemType>

void StackType<ItemType>::Pop()

{

  if( IsEmpty() )

    throw EmptyStack("Pop function");

  top--;

}

template <class ItemType>

ItemType StackType<ItemType>::Top()

{

  if (IsEmpty())

    throw EmptyStack("Top function");

  return items[top];

}

 

Solved
Programming in C,C++ 1 Answer Elif Kurt