Stack

Hi. How can I push an item to the bottom of a stack?

What exactly are you talking about?
i have to push an item to the bottom of a stack if a!=b; do i have to make a recursion ?
for example

if(a==b){
c.push(a);
}
else........
A nun in a orgy makes more sense than this.. A stack of what? integers? strings? Are we walking about std::stack? Using the stack of the actual processor architecture?
Does it really matter what it's a stack of? A stack, as an abstract data type, only have one operation to add elements, and that is at the top of the stack.

HelenI, normally if you have to add something at the bottom you probably shouldn't use a stack in the first place, but I guess you have been given this as a programming exercise so it can be done. Maybe it's easier if you think of something real. Put a stack of plates in front of you. Now the problem is to place another plate under all the other plates but you are only allowed to remove and add one plate at a time from the top of the stack. How would you do this?
> A stack, as an abstract data type, only have one operation to add elements, and that is at the top of the stack, and that is at the top of the stack.

A stack to my knowledge is a contiguous column of memory that has two operations, store and release numerous data types, each one added to the bottom.

To me it would matter what data type it is, as each primitive is of different byte length, an integer would have to decrease the SP by 4 while a char would only be decreased by one.


So yes, it ought to matter right? Not trying to troll or prove you wrong, but when he said push I immediately thought of the assembly instruction, and at that level the type of data would matter.
Helen, are you trying to push an item to the last position of a vector?
A stack to my knowledge is a contiguous column of memory that has two operations, store and release numerous data types, each one added to the bottom.


I guess a stack can have many meanings but this is what I assumed the OP was talking about:
http://en.wikipedia.org/wiki/Stack_%28abstract_data_type%29
hello guys.....my code looks like this..... stack a includes letters, stack b includes a number and stack c includes the numbers 1 or 2. Now i have to check if z is not the same number with c.top() i have to push that item to the bottom.

For example

INPUT:
Α 3 1
Α 2 2
Α 8 1
Κ 2 2
Ζ 3 1
OUTPUT:
Α 8
Α 3
Κ 2
Α 2
Ζ 3




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<iostream>
#include<stack>
using namespace std;

int main(){
stack<char> a;
stack<int>b;
stack<int>c;

int Y,Z,i,N;
char X;
cin>>N;

for(i=0;i<N;i++){
    cin>>X>>Y>>Z;
    if(c.top()== Z){
            a.push(X);
            b.push(Y);
        }
    else


}

}
closed account (SECMoG1T)
it's possible but expensive , you could do this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 void push_to_bottom(stack<int>& stck,int i)
  {
      stack<int> temp;
        
      while(!stck.empty())
       {
          temp.push(stck.top());
          stck.pop();
       }

       stck.push(i);///push your item 

      while(!temp.empty())
        {
           stck.push(temp.top());
           temp.pop();
         }
    }
thank you :)
Topic archived. No new replies allowed.