Question

This implements a static void stack_push(Stack<Integer> stack) for(int i = 0; i < 5; i++) stack.push(i); LinkedList ArrayList
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Stack

It will be the stack because whenever we use stack.push() function all the values will be placed according to stack condition like last in first out

For example;

import java.io.*;

import java.util.*;

class Test

{   

    

    static void stack_push(Stack<Integer> stack)

    {

        for(int i = 0; i < 5; i++)

        {

            stack.push(i);

       }

}

// Displaying element on the top of the stack

    static void stack_peek(Stack<Integer> stack)

    {

        Integer element = (Integer) stack.peek();

        System.out.println("Element on stack top : " + element);

    }

  

    public static void main (String[] args)

    {

        Stack<Integer> stack = new Stack<Integer>();

        stack_push(stack);

        stack_pop(stack);

        stack_push(stack);

        stack_peek(stack);

    }

}

Output:

4

3

2

1

0

Like stack

Add a comment
Know the answer?
Add Answer to:
This implements a static void stack_push(Stack<Integer> stack) for(int i = 0; i < 5; i++) stack.push(i);...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT