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

  Read the matrix from a file called data.txt.

I need to modify this code, instead of asking the user for the matrix, it will read the matrix from a file called Data.txt.

  Find maximum velocity and maximum acceleration

Find maximum velocity and maximum acceleration - Write a general function that can be used to find the maximum of any array. Call this function twice in order to find maximum velocity and maximum acceleration.

  Write programs to play a card game

You will write two programs to play a card game ("clubs"). A separate document describing the rules of "clubs" will be provided.The first program (clubber) will listen on its stdin for information about the game and give its moves to stdout.

  Find the sixth maclaurin polynomial for sin x

Find the sixth Maclaurin polynomial for sin x and use Chebyshev economization to obtain a lesser-degree polynomial approximation.

  How can we definean instance of this class

How can we definean instance of this class?

  Strategies for successful health care marketing

Describe three different strategies for successful health care marketing and public relations.  Which is your personal favorite?  Why?

  Implement at least one additional game feature

Implement at least one additional game feature to the Course Project - You just need to add an additional feature which can be anything.

  Write a c++ statement that stores sunny day

Write a C++ statement that stores " Sunny Day" in str1 - Write a C++ statement that stores the length of str1 into the int variable length.

  Assignment 1 boxing amoebadevelop a two dimensional

assignment 1 boxing amoebadevelop a two dimensional interactive game with the following features1.use opengl any

  A hierarchical jpeg encode decoder for greyscale images

This project is to develop a program that implements a hierarchical JPEG encoder/decoder for greyscale images.

  Create a program that outputs the result of the formula

Create a program that outputs the result of the formula f = (a - b)(x - y) using the printf() functions.

  Suggest an application system which is able to perform some

suggest an application system which is able to perform some arithmetic computations like commission system encryption

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