Dr. Nazli Mollah Data Structures: CSCI 362 – Stack Implementation Data Structures: CSCI 362 – Stack Implementation lecture notes adapted from Data Structures with C++ using STL Stack Implementation Stack Implementation Stacks can be Implemented by: Static Arrays Fixed size Good is size is known Dynamic Arrays Flexible Good if insertion and deletion is infrequent Linked Lists Flexible Dynamic
10
Embed
Data Structures: CSCI 362 – Stack Implementation Data Structures: CSCI 362 – Stack Implementation lecture notes adapted from Data Structures with C++ using.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
lecture notes adapted fromData Structures with C++ using STL
Designing Postfix Evaluation Class for Implementation d_rpn.hDesigning Postfix Evaluation Class for Implementation d_rpn.h
private:String postfixExpression;
// the characters in the string include operands, operators, and white space characters// such as blanks, tabs//These are scanned by the evaluate() function
Stack<int> operandStack;// stack pf operands stored during operations and used by evaluate() function
void getOperands (int& left, int& right);// pops the left and right operands from stack// precondition: checks that the stack is not empty and has at least 2 entries before each pop operation// an empty stack prior to pop() operations indicates that there are too many operators and the// function throws an expressionError exception
int compute (int left, int right, char op) const;// evalautes an operations// pushes result onto a stack// for (/) and remainder (%) operators, compute() checks the RH operator to see if it is 0// If it is 0, the function throws an exressionError exception with the message “Divide by 0”// for the exponentail operator (^), compute() checks for (0,0) and throws an ExpressionError exception
Bool isOPerator (char ch) const;// determines whether a character is one of the valid operators (+, -, *, /, %, ^)