Question: C + + Converting infix to postfix using Stack PLEASE FILL OUT THE CODE IN STACK.H and STACKTEST.CPP Download and unzip Stack.zip, understand Stack.h ,
CConverting infix to postfix using Stack
PLEASE FILL OUT THE CODE IN STACK.H and STACKTEST.CPP
Download and unzip Stack.zip, understand Stack.h then implement a C program to convert infix to postfix. Operands must be alphanumeric, and only the operators and are permitted.
Stackh
#pragma once
#include
using namespace std;
class FullStack
Exception class thrown by Push when stack is full.
;
class EmptyStack
Exception class thrown by Pop and Top when stack is emtpy.
;
struct NodeType
char value;
NodeType next;
;
class Stack
private:
NodeType topPtr;
public:
Stack;
~Stack;
void pushchar x;
void popchar& x;
char top;
bool isFull;
bool isEmpty;
void displayStack;
;
char Stack::top
Returns a copy of the top item in the stack.
Pre: Stack has been initialized.
Post: If stack is empty, EmptyStack exception is thrown;
else a copy of the top element is returned.
if isEmpty
throw EmptyStack;
else
return topPtrvalue;
Stack::Stack Class constructor.
topPtr NULL;
bool Stack::isEmpty
return topPtr NULL;
void Stack::popchar& x
if isEmpty
throw EmptyStack;
x topPtrvalue;
NodeType temp topPtr;
topPtr topPtrnext;
delete temp;
void Stack::pushchar x
if isFull
throw FullStack;
NodeType nodePtr new NodeType;
nodePtrvalue x;
nodePtrnext topPtr;
topPtr nodePtr;
Returns true if there is no room for another ItemType on the free store; false otherwise.
bool Stack::isFull
NodeType nodePtr;
try
nodePtr new NodeType;
delete nodePtr;
return false;
catch std::badalloc exception
return true;
throw FullStack;
void Stack::displayStack
NodeType nodePtr topPtr;
while nodePtr NULL
cout nodePtrvalue ;
nodePtr nodePtrnext;
StackTestcpp
#include
#include "Stack.h
using namespace std;
int main
Stack s;
spusha;
spushg;
spushp;
char ch;
spopch;
cout ch endl;
sdisplayStack;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
