Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Ceate a function that converts from infix expressions to prefix expressions Need to use a string and stack header file which I have added. #ifndef
Ceate a function that converts from infix expressions to prefix expressions
Need to use a string and stack header file which I have added.
#ifndef CS23001_STRING_INTERFACE_HPP #define CS23001_STRING_INTERFACE_HPP #include#include //////////////////////////////////////////////////// // CLASS INV: str[length()] == 0 && // 0 <= length() <= capacity() && // capacity() == STRING_SIZE - 1 // // class String { public: String (); //Empty string String (char); //Stirng('x') String (const char[]); //String("abcd") String (const String&); //Copy Constructor ~String (); void swap (String&); //Constant time swap String& operator= (String); //Assignment Copy char& operator[] (int); //Accessor/Modifier char operator[] (int) const; //Accessor int capacity () const; //Max chars that can be stored (not including null terminator) int length () const; //Number of char in string String operator+ (const String&) const; //Concatenation bool operator== (const String&) const; bool operator< (const String&) const; String& operator+= (const String&); String substr (int, int) const; int findch (int, char) const; int findstr (int, const String&) const; std::vector split(char) const; friend std::istream& operator>>(std::istream&, String&); friend std::ostream& operator<<(std::ostream&, const String&); private: String (int); //String(10) - size of 10. String (int, const char[]); //String(10, "abc") - Size 10 with "abc" void resetCapacity (int); //Resets capacity to be N char *str; //Pointer to char[] int STRING_SIZE; //Size includes NULL terminator }; String operator+ (const char[], const String&); String operator+ (char, const String&); bool operator== (const char[], const String&); bool operator== (char, const String&); bool operator< (const char[], const String&); bool operator< (char, const String&); bool operator<= (const String&, const String&); bool operator!= (const String&, const String&); bool operator>= (const String&, const String&); bool operator> (const String&, const String&); #endif
#ifndef CS2_STACK_HPP_ #define CS2_STACK_HPP_ //////////////////////////////////////////////////////////////////////////// // // File: stack.hpp // // Programmer: // Updated: 10/2017 // // // // #include#include //////////////////////////////////////////////////////////////////////////// // template class Node { public: Node() : next(0) {}; Node(const T &x) : data(x), next(0) {}; T data; Node *next; }; //////////////////////////////////////////////////////////////////////////// // CLASS INV: // // template class stack { public: stack() : tos(0){}; stack (const stack &); ~stack (); void swap (stack &); stack & operator= (stack rhs){swap(rhs); return *this;}; bool empty () const {return tos == 0;}; bool full () const; T top () const; T pop (); void push (const T&); private: Node *tos; }; template void stack ::push(const T& item) { assert(!full()); Node *temp = new Node (item); temp->next = tos; tos = temp; } template T stack ::top() const { assert(!empty()); return tos->data; } template T stack ::pop() { assert(!empty()); T result = tos->data; Node *temp = tos; tos = tos->next; delete temp; return result; } template stack ::~stack() { while(tos != 0) { Node *temp; temp = tos; tos = tos->next; delete temp; } } template void stack ::swap(stack & rhs) { Node *temp = tos; tos = rhs.tos; rhs.tos = temp; } template stack ::stack(const stack & actual) : tos(0){ Node *temp = actual.tos, *bottom = 0; while(temp !=0){ if(tos == 0){ tos = new Node (temp -> data); bottom = tos; } else { bottom -> next = new Node (temp -> data); bottom = bottom -> next; } temp = temp -> next; } } template bool stack ::full() const { Node *temp= new (std::nothrow) Node (); if(temp == 0){ return true; } delete temp; return false; } #endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started