Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 25th European Conference Adbis 2021 Tartu Estonia August 24 26 2021 Proceedings Lncs 12843

Authors: Ladjel Bellatreche ,Marlon Dumas ,Panagiotis Karras ,Raimundas Matulevicius

1st Edition

3030824713, 978-3030824716

More Books

Students also viewed these Databases questions