Help with my project 2

This is a discussion on Help with my project 2 within the C++ Programming forums, part of the General Programming Boards category; Write a program in C++ that evaluates portfix strings (one per line in a text file) with the following restrictions ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Location
    Indiana
    Posts
    99

    Help with my project 2

    Write a program in C++ that evaluates portfix strings (one per line in a text file) with the following restrictions on the input: Each character is either an operand- if it is a digit and the floating point value associated with the digit, or it is one of the 5 binary operators: +, -, *, / (floating point), ^ (exponentiation). You must use a stack, in particular, the linked list implementation of the stack.

    I dont know how to go about this!

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,904
    Please post the your code of what you have tried.


    Please don't open a new post for each question on the same topic.


    Jim

  3. #3
    Registered User
    Join Date
    Feb 2009
    Location
    Indiana
    Posts
    99
    Is there anything you notice that is incorrect about this?
    Code:
    #include<iostream>
    #include<stack>
    using namespace std;
    
    class Lstack {
    private:
    	char Link *top;	/*Pointer to first element*/
    	int size;	/*Count number of elements*/
    public:
    	Lstack(int sz =DefaultListSize) {top = NULL; size = 0;}
    	~Lstack() {clear();}	/*Destructor*/
    	void clear() {
    		while (top != NULL) { /*Delete link nodes*/
    			Link* temp = top;
    			top = top->next;
    			delete temp;
    		}
    		size = 0;
    	}
    	bool push(const Elem& item) {
    		top = new Link(item, top);
    		size++;
    		return true;
    	}
    	bool pop(Elem& item) {
    		if(size == 0) return false;
    		it = top->element;
    		Link *ltemp = top->next;
    		delete top;
    		top = ltemp;
    		size--;
    		return true;
    	}
    	bool topValue(Elem& it) const {
    		if (size ==0) return false;
    		it = top->element;
    		return true;
    	}
    	int length() const {return size;}
    	bool isEmpty() const {
    		if (top == NULL) return true;
    		else return false;
    	};
    int main(){
    	return 0;
    }

  4. #4
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,652
    Code:
    Lstack(int sz =DefaultListSize) {top = NULL; size = 0;}
    If you're passed the size, wouldn't you really like to use the size?

    Why have boolean methods that never return anything but true?

    Shouldn't pop, actually, well...pop something?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 10:05 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 02:30 PM
  3. Dynamic Binding
    By gpr1me in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 09:01 AM
  4. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 08:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21