Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

remove minimum element from stack java

public static void removeMin(Stack stack) {
        int min = stack.readTop(); 
        int e;
        Stack newStack1 = new Stack(7); //7 is the size of the stack
        while (!stack.isEmpty()) {
            e = stack.pop(); 
            newStack1.push(e); 
            
            if (e < min) {
                min = e;
            }
        }

        System.out.println("
Min element: " + min);

        while (!newStack1.isEmpty()) {
            e = newStack1.pop(); 
            
            if (e != min) {
                stack.push(e);
            }
        }
    }
 
PREVIOUS NEXT
Tagged: #remove #minimum #element #stack #java
ADD COMMENT
Topic
Name
7+1 =