Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- while( getline(inputss, input, ' ') ){
- char *charPointer = new char[input.length()]; //a character pointer used to make the transition from string to character
- strcpy ( charPointer,input.c_str() );
- if ( isalpha(*charPointer) || isdigit(*charPointer) )
- cout << charPointer;
- else if ( (*charPointer == '('))
- operatorStack.push(*charPointer);
- else if ( (*charPointer == ')')){
- while (!operatorStack.empty() && operatorStack.top() != '(') {
- cout << operatorStack.top();
- operatorStack.pop();
- }
- if ( !operatorStack.empty() )
- operatorStack.pop();
- else {
- cout << "Error incorrect input format, missing ')' " << endl;
- return 0;
- }
- }
- else if ((!operatorStack.empty()) || (precidence(operatorStack.top())) < (precidence(*charPointer))) //empty stack has lowest precidence.
- operatorStack.push(*charPointer);
- else if ((precidence(operatorStack.top())) >= (precidence(*charPointer))) {
- while (!operatorStack.empty() && (precidence(operatorStack.top())) >= precidence(*charPointer)){
- cout << charPointer;
- operatorStack.pop();
- }
- operatorStack.push(*charPointer);
- }
- else
- cout << "Error, incorrect input. Exiting Program." << endl;
- }// end of while loop
Add Comment
Please, Sign In to add comment