Build a program to implement the selection sort algorithm

Assignment Help Computer Engineering
Reference no: EM1327747

1. Draw the decision tree for the insertion sort algorithm for the following array of names: [Mickey, Minnie, Donald, Goofy].

2. Create a program to implement the selection sort algorithm, which will sort a list of strings. Selection sort function should sort the list of strings in alphabetical order. You only need to provide the details for the selectionSort() function based on the given framework.

#include < iostream >
#include < string >
#include < stdlib.h >

using namespace std;
void selectionSort(string items[], int numberOfItems)
{
//
// Hints:
// (1) You will need two for loops.
//
// (2) Use the strcmp() function in your if-statement
// to determine when one string is less than another.
// You will need to call this function with the c_str()
// method. For example:
// strcmp(items[i].c_str(), items[j].c_str());
//
// (3) You will need a temporary string when swapping
// the two strings.
//
return;
}

// Print the items in the list.
void printItems(string items[], int numberOfItems)
{
for (int i=0; i < numberOfItems; i++)
{
cout << items[i] << endl;
}
cout << endl;
return;
}

int main(int argc, char **argv)
{
string starTrekCharacters[] = {
"Picard", "Riker", "Data", "La Forge", "Worf", "Dr. Crusher",
"Dr. Pulaski", "Wesley", "Troi", "Tasha", "Sisko", "Odo",
"Dax", "O'Brien", "Quark", "Dr. Bashier", "Kira", "B'Elanna",
"Chakotay", "Janeway", "Neelix", "Seven of Nine", "Tuvok",
"Doctor", "Harry", "Tom", "Kes", "Archer", "T'Pol", "Tucker",
"Reed", "Travis", "Hoshi", "Dr. Phlox", "Kirk", "Spock",
"Bones", "Scotty", "Chekov", "Uhura", "Sulu", "Nurse Chapel"
};

int numberOfCharacters = 41;

// Print the unsorted items

cout << "Items unsorted:" << endl;

printItems(starTrekCharacters, numberOfCharacters);

// Sort the items

selectionSort(starTrekCharacters, numberOfCharacters);

// Print the sorted items

cout << "Items sorted:" << endl;

printItems(starTrekCharacters, numberOfCharacters);

return 0;

}

Reference no: EM1327747

Questions Cloud

Exercises which can improve student learning : What are some activities and exercises that can improve a student's learning in this area? What are the current and future applications and revelance to the workplace?
Who should lead the migration plan from an existing process : Leading Departmental Change - What should be included in the term "systems" as related to the department? Does the term include people? Explain.
Application and implication of laws : Explain the application and implication of the following laws for your employer. Be sure to analyze (but is not limited to) the following employee safety, health.
Four most important ways a firm''s international strategy : What are the four most important ways a firm's international strategy can be related to its competitive advantage?
Build a program to implement the selection sort algorithm : build a program to implement the selection sort algorithm, which will sort a list of strings. Selection sort function should sort the list of strings in alphabetical order. You only need to provide the details for the selectionSort() function base..
Suppose demand for abc product has an elasticity coefficient : Suppose the demand for ABC product has an elasticity coefficient. Explain how many it will sell per month if the price
Steps-restore organizational growth-halt decline by leaders : What steps can organizational leaders take to halt decline and restore organizational growth?
Explain external and internal factors analysis - nestle : Explain External and Internal Factors Analysis - Nestle and using your research findings from the Library and the Internet
Show the common business practices : Common Business Practices - Human resources needs to be able to track employees from recruitment to retirement, including roles, salary, compensation, benefits selected, annual reviews, competencies, skills and training taken.

Reviews

Write a Review

 

Computer Engineering Questions & Answers

  What is standard purchasing system

SPS system would standardize purchasing practices for each Snad and Surf subsidiary and manage all purchasing information. System testing will be completed by end of the week. What kinds of documentation are required for this application?

  Plan an algorithm that finds k smallest numbers

plan an algorithm that finds k smallest numbers of the whole G sorted in ascending order and has time complexity O(m*lg(m)) and spatial complexity O(m).

  Computing the unit price of items

The Manager of the Supermarket would like to be able to compute the unit price of items sold there. To do this the program must input the name and the price of item and its weight in pounds and ounces.

  A system that calculates and returns the mean and a method

A system that calculates and returns the mean and a method

  Security devices for protection against different attack

Describe two or more attacks for which the routers (layer 3 devices) are vulnerable. Explain how these attacks are detected and prevented by the security devices.

  Modify compound interest program

Modify compound interest program

  Methods to target certain audience

Recognize a particular website which you frequently go to and explain the targeted audience which visit that particular site. Provide explanation how the site is developed for its certain target audience.

  Hardware tools need to search cell phone

After looking upon the warrant this search and seizure is justified thus, your team now should search the cell phone for the digital evidence. Explain the hardware tools required to search this cell phone?

  More detail to be shown as a process is exploded

In data flow diagrams (DFDs), a process symbol can be referred to as a black box, becase the inputs, outputs, and general funcions of the process are known, but the underlying details and logic of the system are hidden.

  Execute a set adt in java using a singly linked list

Execute a Set ADT in Java using a singly linked list

  Developing program for real estate agent in java language

Write down a java program for the real estate agent. The program must carry out the following tasks: Ask the users for average house price for the each of the past 5 years for the single family residence of 1500 square feet.

  Write an essay on wifi performance

Write an essay on WiFi performance

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