• + 1 comment

    What is the issue with doing enqueue and the other methods this way?

    public void enqueue(T value) { // Push onto newest stack
            	for(int i = 0; i < stackOldestOnTop.size(); i++){
            		stackNewestOnTop.push(stackOldestOnTop.pop());
            	}
            	stackNewestOnTop.push(value);
            	for(int j = 0; j < stackNewestOnTop.size(); j++){
            		stackOldestOnTop.push(stackNewestOnTop.pop());
            	}	
            }
    
            public T peek() {
                 if(!stackOldestOnTop.isEmpty())return stackOldestOnTop.peek();
                 return null;
            }
    
            public T dequeue() {
                if(!stackOldestOnTop.isEmpty())return stackOldestOnTop.pop();
                return null;
            }
        }