0% found this document useful (0 votes)
22 views1 page

Assignment 1.2

The document provides 3 questions to write Java programs that implement and use stacks and queues. Question 1 asks to implement a stack with methods like push, pop, top, and traverse and use it to convert decimal to binary. Question 2 asks to implement a queue with methods like enqueue, dequeue, first, and traverse and use it to convert decimal to binary. Question 3 asks to convert an infix expression to postfix form.

Uploaded by

NHT Gamevui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views1 page

Assignment 1.2

The document provides 3 questions to write Java programs that implement and use stacks and queues. Question 1 asks to implement a stack with methods like push, pop, top, and traverse and use it to convert decimal to binary. Question 2 asks to implement a queue with methods like enqueue, dequeue, first, and traverse and use it to convert decimal to binary. Question 3 asks to convert an infix expression to postfix form.

Uploaded by

NHT Gamevui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

2-Stacks and Queues

Practical exercises
Question 1. Write a Java program to implement a stack of integer values with the following
operations:
1. boolean isEmpty() - return true if the stack is empty and false otherwise.
2. void clear() - clear the stack.

3. void push(int x) - insert a node with value x at the top of the stack.
4. int pop() - remove the top element on the stack and return it's value; throw
EmptyStackException for empty stack.
5. int top() - return value of a node at the top of the stack; throw EmptyStackException
for empty stack.
6. void traverse() - display all values in the stack from the top to the bottom.
7. Use a stack to convert an integer number in decimal system to binary system and display on
the screen.
Note: You can write some constructors and other methods as you see they are necessary.

Question 2. Write a Java program to implement a queue of integer values with the following
operations:
1. boolean isEmpty() - return true if the queue is empty and false otherwise.
2. void clear() - clear the queue.
3. void enqueue(int x) - insert a node with value x at the end of the queue.
4. int dequeue() - remove the first element on the queue and return it's value; throw Exception
for empty queue.
5. int first() - return value of the first node of the queue; throw Exception for empty queue.
4. void traverse() - display all values in the queue from the front to the rear.
6. Use a queue to convert a real number less than 1 in decimal system to binary system
and display on the screen.
Note: You can write some constructors and other methods as you see they are necessary.

Question 3. Change the infix form to postfixform.

You might also like