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

  Implement a program to process a weighted undirected graph

Read in the number of vertices V and the number of edges E of the graph followed by its E edges, each in the form u, v, w where 1 0 representing an edge uv with weight w.

  Write a c++ statement that outputs the data stored

Write a C++ statement that declares student to be a personType object, and initialize its first name to "Buddy" and last name to "Arora".

  Returns the value of the arithmetic sum up to n

Write and test the following function that returns the value of the arithmetic sum up to neg. SumUpto(5) = 5+4+3+2+1 =15int SumUpto(int)

  Sentinel security product prototype description

Sentinel Security Product Prototype Description - The paper should describe innovative aspects of your product and persuade the stakeholders of the intrinsic value of your product.

  Create your own function

Create your own function in C that accepts one input parameter and returns a float number. You decide the theme. You should C code and an example call. Be sure to provide an overview of what your function is doing

  First display the smallest volume and then the largest volum

first display the smallest volume and then the largest volume.

  Write specifications for a method

Write specifications for a method that advances any given date by one day. Include a statement of purpose, pre- and post-conditions, and a description of the parameters.

  Dynamicword that holds a pointer

Consider the following main function.  Assume that DynamicWord.h contains a class definition for a class called DynamicWord that holds a pointer to a dynamic array as a private data member, but the assignment operator (=) has not been overloaded for ..

  Define a string of four characters and converts

Write an assembly program that defines a string of four characters and converts it into an unsigned 16-bit integer.

  A parking garage charges a $2.00 minimum

A parking garage charges a $2.00 minimum fee to park for up to three hours and an additional $0.50 per hour for each hour or part thereof over three hours.

  Take four unsigned char bytes and combine

Take four unsigned char bytes and combine them into a single integer type. You will needed shifts and one of the logical bit operators.

  Determining the purchase of new aircraft

Southern Air is considering purchase of new aircraft and has set aside $1.5B dollars for this. They have enough pilots to crew 30 new planes and enough maintence personnel to crew 40 new short range planes.

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