CS 351 Homework 2

Description

Run this assignment in JGRASP Softwere

Don't use plagiarized sources. Get Your Custom Assignment on
CS 351 Homework 2
From as Little as $13/Page

Unformatted Attachment Preview

Homework #2
CS 351.001
Spring 2024
Data Structure II
50 Points
Due: 02/26/2024, 11:59 PM
Read the questions thoroughly. Points will be deducted if the instructions are not
followed properly. Upload the .java files on the Western Online Homework 2
assignment page. Do not upload .class or .PDF files.
1. Write a Java program to create a Singly Linked List, which contains N integer
elements in N number of nodes. Read the value of N and elements from the user.
Now print the linked list elements in reverse order with the help of a Stack data
structure. You can use Java built-in LinkedList and Stack classes in your code. The
sample inputs/ outputs are given below:
(10 Points)
Sample inputs and outputs:
(User’s inputs are shown in bold)
Enter the number of nodes of linked list: 5
Enter the element 1: 2
Enter the element 2: 9
Enter the element 3: 3
Enter the element 4: 7
Enter the element 5: 5
The content of the linked list in reverse order: 5 7 3 9 2
2. Write a Java program to take an arithmetic expression from the console. The
expression must contain the parenthesis, operators (only +, -, *, /, and %), and
operands. Check the validity of the expression with respect to the position of
opening and closing parenthesis. Print an appropriate message if the expression is
invalid; otherwise, convert the expression into its postfix form, print the postfix form,
and then evaluate that postfix expression and print the result. The postfix expression
may contain double-digit operands. You can use Java built-in Stack. Separate
operators, operands, and the parenthesis by white spaces. Print the postfix
expression in the same manner. The program must continue unless the user types
in N or n. The sample inputs/ outputs are given below:
(15 points)
Sample inputs and outputs:
(User’s inputs are shown in bold)
Enter the expression: 12 + ( 2 + 13 ) * 20 )
The expression is invalid.
Do you want to continue (Y/ N)? Y
Enter the expression: 12 + ( 2 + 13 ) * 20 % 8
The postfix expression: 12 2 13 + 20 * 8 % +
The final result: 16
Do you want to continue (Y/ N)? N
Thank you!
3. Assume you are developing an operating system that follows a Round-Robin (RR)
process scheduling algorithm. In the RR scheduling, processes are allocated to the
CPU for execution as per their arrival sequence for a fixed period of time (also
known as time quanta). If the process is not executed fully, it is taken off the CPU
and sent to the end of the process queue for its next turn. Write a Java program in
Java to implement the RR scheduling algorithm using a Singly Circular Linked
List. Users can execute as many processes as they wish. Assume the initial arrival
time of each process is the same. Your program will insert the processes in the
process queue, allocate the processes one by one to the CPU for execution, and
print appropriate messages depending on the situation. You can use relevant Java
built-in classes in your code. Read the time quanta, the total number of processes,
each process’s name, and its execution time from the user. Print the current process
queue along with each process’s remaining execution time after each round of
execution. The sample inputs/ outputs are given below:
(25 points)
Sample inputs and outputs (User’s inputs are shown in bold):
Enter the total number of processes: 3
Enter the time quanta: 100
Enter the name of process 1: P1
Enter its execution time: 200
Enter the name of process 1: P2
Enter its execution time: 90
Enter the name of process 1: P3
Enter its execution time: 350
The process queue: P1, 200 P2, 90
Execution phase:
P3, 350
The process queue: P2, 90
P3, 350
P1, 100
The process queue: P3, 350
Process P2 is executed
P1, 100
The process queue: P1, 100 P3, 250
The process queue: P3, 250
Process P1 is executed
The process queue: P3, 150
The process queue: P3, 50
The process queue is empty
Process P3 is executed

Purchase answer to see full
attachment