ok this is what I got so far. Is there anything you notice that I have incorrect?
Yes....
Code:
int main(){
bool push(const Elem& item){
if(top == size) return false; /* Stack is full*/
else {listArray [top++] = item;
return true;
}
}
bool pop(Elem& item){ /*Pop top element*/
if(top == 0) return false;
else {item = listArray[--top];
return true;
}
}
bool topValue(Elem& item) const { /*Return top element*/
if (top == 0) return false;
else {item = listArray[top - 1];
return true;
}
}
int length() const {return top;}
bool IsEmpty() const {if(top == 0) return true;
else return false;
}
}
In this code you are trying to define functions inside main(). For now just put main at the bottom of your file.
Like:
Code:
bool push(const Elem& item){
if(top == size) return false; /* Stack is full*/
else {listArray [top++] = item;
return true;
}
}
bool pop(Elem& item){ /*Pop top element*/
if(top == 0) return false;
else {item = listArray[--top];
return true;
}
}
bool topValue(Elem& item) const { /*Return top element*/
if (top == 0) return false;
else {item = listArray[top - 1];
return true;
}
}
int length() const {return top;}
bool IsEmpty() const {if(top == 0) return true;
else return false;
}
}; ///////////// Notice the semicolon ///////////////////////
int main()
{
return(0);
}
Now does the code compile?
No? What are the error messages? Please post the entire error messages, along with the modified code.
Yes? Great. Now try to use the class.
Jim