Question: 3. Sorting. a. Implement a generic Stack linked list data structure for integers that supports these functions: i. InsertionSort), which runs an insertion sort algorithm

 3. Sorting. a. Implement a generic Stack linked list data structure

3. Sorting. a. Implement a generic Stack linked list data structure for integers that supports these functions: i. InsertionSort), which runs an insertion sort algorithm on the stack 1. Your insertionSort()algorithm should print to the console every time it makes a swap. Print the operation performed ("Swapped a with b"), then on the next line print the current contents of the array. Print to the console when the sort has finished ("Sort finished!") ii. iii, iv. 2. Push(int data), which pushes values to the head of the stack Pop(), which pops values from the head of the stack and returns it Peek(), which returns a value from the head of the stack b. Implement a pastPeek() function such that it always peeks the head of the stack prior to the sort taking place. When the head of the stack is popped from the sorted stack, update peek() to move to where the next head would have been. i. Example: Insert: 10,4,14,9,3 ii. Sort: 3,4,9,10,14 ii. pastPeek()->returns 3 iv. Pop->removes 3 v. pastPeek()-> returns 9 vi. Pop->removes 4 Make sure the data structure operation is preserved independently of InsertionSort() being called. Make all appropriate considerations for program crashes with proper error handling using exceptions. Follow the same instructions as 1b

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!