Implement a selection sort

Assignment Help C/C++ Programming
Reference no: EM131213416

This program involves using STL lists.

For this program you will implement three functions whose prototypes are given below:

list<int>::iterator mxIter(list<int>::iterator first,
list<int>::iterator last);

void selectSort(list<int>& aList);

void writeList(const list<int>& alist);

What you need to do:

You are going to use a static array declared using { 12, 1, 6, 8, 5, 9, 22, 9, 13, 17 } to initialize an STL list, as shown in the slides.

Then you will implement a selection sort (selectSort). A selection sort involves sweeping over the list and finding the maximum element of the list (by calling MxIter) that has not already been sorted, creating a new element at the beginning of the list, setting its value to be the same as the maximum element's value, and then deleting the maximum element (using erase).

Note that you need to keep track of the beginning of the unsorted part of the list. This is straightforward unless the beginning of the unsorted part of list needs to change due the the erasing of the node currently at the beginning of the unsorted part of the list, i.e. you don't need to change this iterator unless it is "pointing" at an element of the list that will be deleted.

The creation of a new node at the front of the list and deletio of a node in the unsorted part of the list occurs n times, where n is the size of the list. Note that in the nth iteration, the smallest element in the original list is moved to the beginning of the sorted list. When the sorting is completed, the list will contain, from left to right, minimum element to maximum element.

The function mxIter is called to find the maximum element in the unsorted part of the list. It returns an iterator that "points" to the maximum element.

The writeList function is used to print out the initial contents of the list and the final contents of the list. The output of the program should be:

Unsorted list: 12 1 6 8 5 9 22 9 13 17

Sorted list: 1 5 6 8 9 9 12 13 17 22

Reference no: EM131213416

Questions Cloud

Management characteristics or job characteristic : Dissertation on "To determine whether it is management characteristics, or job characteristic, that have the greatest influence on engagement in a Liberian insurance company"
Networking models used for communications : Assuming you resolved the beginning of this chapter's modeling activity, how would you compare the following steps taken to design a communications system to the networking models used for communications?
Design a voltage divider to provide the approximate : The number of resistors, their values, and their wattage ratings must be specified. A schematic showing the circuit arrangement and resistor placement must be provided.
Determining the binary strings of length : Prove that for every positive integer n, there exists a set S of binary strings of length n that contains 2n-1strings no two of which differ in only one position. (There are multiple ways to prove this, not all of which involve induction. You need ..
Implement a selection sort : Implement three functions whose prototypes are given - You are going to use a static array declared using { 12, 1, 6, 8, 5, 9, 22, 9, 13, 17 } to initialize an STL list, as shown in the slides.
Identify and describe a current issue in american government : Identify and describe a current issue (this could be a controversy or just an issue of importance) in American Government. Explain in 1-2 pages how one of the modern philosophers we've studied would respond to that issue.
What do we know about the mitzvah of giving charity : What is the source for the Mitzvah of Giving Charity in Jewish Tradition? Based on this week's lecture, what do we know about the Mitzvah of Giving Charity? How do we know?
What is the capital balance of the remaining three partners : Assume that the partners share profits and losses 4:3:2:1, respectively. Pnda retires and is paid $305,000 based on the terms of the original partnership agreement. If the bonus method is used, what is the capital balance of the remaining three partn..
Rectangular array of numerical values : A matrix is a rectangular array of numerical values. You can add or multiply two matrices to form a third matrix. You can multiply a matrix by a scalar, and you can transpose a matrix.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd