Arrays - Stacks and Queues - Data Structures - IT Assignment Help

Download Solution Order New Solution
Assignment Task:

Objective:
The main goal of the assignment is to get familiar with the stack and queue data structures and get practice while implementing. Along with it, you will get to explore these data structures in the context of their applications.

Part A:

Problem Statement:
Implement the stack data structure. You must implement the class with the following methods. It must be a generic class (i.e. you can specify the data type while creating the object). You are being provided with the Interface with signatures of the functions and you need to complete the code to implement the desired functionality.
 
1. MyStack(): Constructor for MyStack class. Initialize an empty array of type T. 
2. void push(T value): Insert the value at the top of the stack. Resize if the internal array is full. 
3. T pop() throws edu.iitd.col1062020.EmptyStackException: Delete the top element of the stack, and return it. If the stack is empty, you must throw the specified exception. 
4. T top() throws edu.iitd.col1062020.EmptyStackException: Return the top element of the stack. If the stack is empty, you must throw the specified exception. 
5. boolean isEmpty(): Returns true if the stack is empty, false otherwise. 

Part B:

Problem Statement:
In this part, you will use your above implementation to implement a simple calculator. You will be given a String representing a valid arithmetic expression, and you will have to evaluate the expression and find the result. The expression String may contain open ( and closing parentheses ), the plus +, minus - or multiplication * sign, non-negative integers and empty spaces. You may assume that the given expression is always valid.

You must implement the class edu.iitd.col1062020.calculator with the following methods. As before you are provided with the Interface with signatures of the functions and you need to complete the code. 
1. calculator(): Constructor for the MyCalculator class. 
2. int calculate(String expression): Find the value of the expression using the MyCalculator class implemented above. 

Part C:
 
Problem Statement:
In this part, you will use the stack implementation from Part A to sort a given array. You are given an array of integers and you have to sort it using a single stack A. You are allowed to only push elements from the given array of integers (treating it as a queue), and your sequence of pops should form a sorted sequence of the given array. You have to return the sequence of operations (described below) in order to sort the elements.

Allowed operations: 
1. Extract one input element (with least index) and insert in the stack. Represented as PUSH. 
2. Pop the top-most element of the stack. Represented as POP. 
3. If it is not possible to sort the given numbers with a single stack, then NOT POSSIBLE.
 
Return the sequence of operations as an Array of String. Your sequence should correspond to a valid sequence of operations, and the pop sequence should form a sorted array of given numbers (in ascending order). Your number of PUSH and POP should be exactly equal to the length of the given array of numbers. 

Part D:
 
Problem Statement:
In this part, you will extend the above implementation, to sort the array by repeatedly using the stack. Let us denote the operation applied in Part C by f, then on applying f to the input array of numbers, you get another array of numbers, on which you can reapply this f. You are allowed to do the above procedure as many times as you like, provided it results in a sorted array at the end. You need to find the least k, such that applying the operation f, k times leads to the sorted array.
 
Return the sequence of operations as an Array of String, with the outer Array of length k, the least number of operations in which you can sort the input array of given numbers. Your sequence should correspond to a valid sequence of operations, and the sequence should form a sorted array of given numbers (in ascending order) at the end of the last operation.


This IT Assignment has been solved by our IT Experts at My Uni Paper. Our Assignment Writing Experts are efficient to provide a fresh solution to this question. We are serving more than 10000+ Students in Australia, UK & US by helping them to score HD in their academics. Our experts are well trained to follow all marking rubrics & referencing style.

Be it a used or new solution, the quality of the work submitted by our assignment experts remains unhampered. You may continue to expect the same or even better quality with the used and new assignment solution files respectively. There’s one thing to be noticed that you could choose one between the two and acquire an HD either way. You could choose a new assignment solution file to get yourself an exclusive, plagiarism (with free Turnitin file), expert quality assignment or order an old solution file that was considered worthy of the highest distinction.

Get It Done! Today

Country
Applicable Time Zone is AEST [Sydney, NSW] (GMT+11)
+

Every Assignment. Every Solution. Instantly. Deadline Ahead? Grab Your Sample Now.