Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stackIOint.hh"
- void pertstack_it(stack<parint> &S, int i);
- int main()
- {
- stack<parint> p;
- llegir_stack_int(p,0);
- cout << "Escriu opció -1 per modificar la pila original o -2 per fer-ne una de nova:" << endl;
- int n = readint();
- cout << "Escriu la component k a sumar:" << endl;
- int valor=readint();
- if (n == -1) {
- pertstack_it(p, valor);
- }
- else {
- stack<parint> copia(p);
- pertstack_it(p, valor);
- }
- escriure_stack_int(p);
- }
- void pertstack_it(stack<parint> &s, int i)
- /* Pre: s = S */
- /* Post: La pila qeda modifica el segon component que se li suma i */
- {
- stack<parint> n;
- parint x;
- while (not s.empty()){
- x = s.top();
- x.n2 += i;
- n.push(x);
- s.pop();
- }
- while (not n.empty()){
- x = n.top();
- s.push(x);
- n.pop();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement