0% found this document useful (0 votes)
12 views

Java 4

Create a java program to implement stack and queue concept.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Java 4

Create a java program to implement stack and queue concept.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Program - 04

Aim: Create a java program to implement stack and queue concept.

Code:
import java.util.LinkedList;

import java.util.Queue;

import java.util.Stack;

public class Main {

public static void main(String[] args) {

System.out.println("Name - Ankit\n"+"Roll No. - 221901206");

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

Queue<Integer> queue = new LinkedList<>();

stack.push(1);

stack.push(2);

stack.push(3);

System.out.println("Stack elements: " + stack);

stack.pop();

System.out.println("Stack elements after popping: " + stack);

System.out.println("Peek element of stack: " + stack.peek());

queue.add(1);

queue.add(2);

queue.add(3);

System.out.println("Queue elements: " + queue);

queue.remove();

System.out.println("Queue elements after removing: " + queue);

System.out.println("Peek element of queue: " + queue.peek());

}
Output:

You might also like