generate functionSun, 18 Jun 2023

método que apila pilas, recibiendo como parámetro una pila, sin utilizar pop, ni stack

public static Stack<Integer> addStack(Stack<Integer> stack) { Stack<Integer> aux1 = new Stack<Integer>(); Stack<Integer> aux2 = new Stack<Integer>(); while(!stack.empty()){ aux1.push(stack.pop()); } while(!aux1.empty()){ int num = aux1.pop(); aux2.push(num); stack.push(num); } return aux2; }

Questions about programming?Chat with your personal AI assistant