Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Insertion sort is an algorithm for sorting an array of values into ascending order. It works by using two loops, an outer loop that scans

Insertion sort is an algorithm for sorting an array of values into ascending order. It works by using two loops, an outer loop that scans the data once, and an inner loop that scans from position of the outer loop counter to the start of the array, looking for a suitable spot to place the current element being sorted. Insertion sort has (2) running time, unless the input is already sorted, in which case the running time is ().

Typically, an array of unsorted values is the input to insertion sort. In this assignment, you will implement the insertion sort algorithm (see pseudocode below) on a doubly-linked list (instead of an array).

image text in transcribed

A doubly-linked list is just a linked list where each node in the list has both a pointer to the next node and a pointer to the previous node. The first node in the list has a nullptr to its previous node. The last node in the list has a nullptr to its next node.

Step 1: create your own doubly-linked list class in c++

INSERTION-SORT(A) 1 for j - 2 to length[A] 2 do key + A[j] 3 Insert A[j] into the sorted sequence A[1.. j - 1]. 4 ir j - 1 5 while i > 0 and A[i] > key 6 do A[i+1] + A[i] 7 iti - 1 8 A[i+1] + key

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

Hands On Database

Authors: Steve Conger

1st Edition

013610827X, 978-0136108276

More Books

Students also viewed these Databases questions

Question

=+Where does the focus of labor relations lie? Is it collective

Answered: 1 week ago