Your fill
function takes the parameter a
by value, which means a copy is made. No changes to a
inside the function will affect the variable you passed to the function.
I suggest you make the function pass the object by reference:
void fill(stack<int>& a, int cap)
Now changes to a
will update the object your passed. The fact that you may be passing a global variable to the function doesn’t matter here.
1
solved how to work on stl stacks inside functions c++? [closed]