If I have declared the following:
stack <what> name;
struct what
{
int value;
string value2;
};
How do I push value and value2 on to the stack and how do I output the individual contents?
Thank You
If I have declared the following:
stack <what> name;
struct what
{
int value;
string value2;
};
How do I push value and value2 on to the stack and how do I output the individual contents?
Thank You
Initialize struct what's data members before pushing the struct into the stack. You cannot modify an element in a stack.
Kuphryn
but how do initialize the data?
do i say
cin >> what.value;
cin >> what.value2;
and how do i then push those items on to the stack. basically, what is the syntax?
Incorrect.Originally posted by kuphryn
You cannot modify an element in a stack.
The first element may be modified.
Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling
okay, i want to push values on to the stack. coming from a struct...
how do i do this? how do push the values and how do i output the values?
what w[2] = {{4, string("Hello")}, {5, string("Bye")}};
name.push(w[0]);
name.push(w[1]);
what w1 = name.top();
name.pop();
what w2 = name.top();
name.pop();
Like queue, stack is designed to be permanent. Yes, there are two version of top() and one of them returns a reference to the element. Nonetheless, I believe you should not attemp to modify an element since you may only modify the top element.
Kuphryn