Category : stack

Normally when we use stack we do this…. stack<int>st; st.push(1); st.push(2); st.push(3); cout<<st.top<<"n" But my question is how to push and access data when we use struct instead of int/char type variable? For example… struct st { int index, value; }; int main() { stack<st>STACK; /* code */ } Now, here how can I push ..

Read more

I want to assign the values in stack to the string without using the method used below. Are there any possible ways/method to perform this in C++? *Assuming there are character values present in the stack. stack<char> K; string ans=""; while(!K.empty()){ ans+=K.top(); K.pop(); } reverse(ans.begin(),ans.end()); return ans; Thank you in advance. Source: Windows Que..

Read more

Line 30: Char 11: error: no matching member function for call to ‘push’ s1.push(root); ~~~^~~~ /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_stack.h:233:7: note: candidate function not viable: no known conversion from ‘Node *’ to ‘const std::stack<TreeNode *, std::deque<TreeNode *, std::allocator<TreeNode *>>>::value_type’ (aka ‘TreeNode *const’) for 1st argument push(const value_type& __x) ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/bits/stl_stack.h:238:7: note: candidate function not viable: no known conversion from ..

Read more