Implement functions whose prototypes are shown

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

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).

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

Verified Expert

Brief description of the solution In the following code, we are performing selection sort using the following steps- - Find the maximum element in the list - Insert the element in the beginning - Check if the first element is max, if yes, move the first iterator ahead - Perform the above in a loop for the size of the list - Display the sorted list on the screen.1) Ease of usage of the data structure std::list In the following code, we can see that using 'std::list type makes it very easy for us to perform selection sort. It has readily available functions for inserting and erasing an element, which is a very necessary step performed during sorting.

Reference no: EM131213442

Questions Cloud

Create a flowchart that will contain two modules : Create a flowchart that will contain two modules, one to prompt the user to input the sales amount, and the other to calculate the amount of sales tax on that sales amount.
What is the profit for each dollar used initially : How would you engage in arbitrage to profit from these three rates? What is the profit for each dollar used initially?
Juveniles in criminal court : Given the concerns raised about juveniles being tried in criminal court, should this practice continue? Why or why not? As appropriate, cite the online course, the textbook, and other credible, scholarly sources to substantiate the points you are m..
What are the effects of each of given exchange rate : The spot exchange rate between the dollar and the Swiss franc is a floating, or flexible, rate. - What are the effects of each of the given on this exchange rate?
Implement functions whose prototypes are shown : Implement three functions whose prototypes are given below - 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 va..
Discuss stable versus unstable ones : A sorting algorithm is stable if elements with equal keys are left in the same order as they occur in the input. Look at the sorting algorithms presented in this chapter. Discuss stable versus unstable ones.
What is the most successful child-rearing style : Define public policy and discuss how Americans fare on key measures of childhood health and well-being and policies for the elderly. Then explain how both affluence and poverty can negatively affect development.
What intervention is necessary by the monetary authorities : What intervention is necessary by the monetary authorities to defend the fixed rate if the change shifts the intersection of private supply and demand outside the band?
Trade-offs between system scalability : Explain the trade-offs between system scalability and system transparency you may encounter when designing a large-scale system.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Write a function named flattens

Write a function named flattens that takes a two-dimensional array of integers with 100 rows and 200 columns and returns a vector that contains all of the array's elements.

  Examine the differences between a linear and augmented line

"Developing a Website" Please respond to the following: Examine the differences between a linear and augmented linear structure. Examine the differences between hierarchical and linear structures. Explain why a coherent structure is necessary. Provid..

  Computing the standard deviation

Input Details: The scores are entered as numbers with or without decimal points. In response to the continuation prompts (described below) the user types a y or a Y to signify "continue" with any other character signifying "quit".

  Program that translates a letter grade into a number grade

Write a program that translates a letter grade into a number grade. Letter grades are A, B, C, D, and F, possibly followed by + or -.

  Use a define statement to create a constant

Follow these specifications: Use a define statement to create a constant that will hold your student number. You should have separate string variables for your first and last name; name these first_name and last_name.

  Implement a function called findmax

Implement a function called findMax that finds the maximum value in a 2¬dimensional array.

  Define a class that consists of three objects

Define a class that consists of three objects: day, month, and year. Within this class define two member function (constructor ) to initialize the objects to today?s date and one that display the date as follows: 05/7/2002

  Write a c program for the microcontroller to send a pattern

Write a C program for the 68HCS12 microcontroller to send the pattern 0x55 to byte-sized Memory Location "OUT1" and then call a delay function.

  Creates an array of six divsales objects

Write a program that creates an array of six DivSales objects. The program should ask the user to enter the sales for four quarters for each division. After the data are entered, the program should display a table showing the division sales for ..

  Presented a number of recurrence relations

For this problem set, you will be presented a number of recurrence relations and asked to state their actual time complexity, showing your work in the process.

  Computer graphicsdevelop a simple interactive

computer graphicsdevelop a simple interactive two-dimensional spaceship deck plan editor using opengl and glut. your

  What is realistic rendering in computer graphic

Differentiate between pillar boxing and the letter boxing. What is realistic rendering in computer graphic. Discuss the approach used in realistic rendering.

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