For assignment 5, you will be writing a sort for the words in a provided diction
ID: 3827219 • Letter: F
Question
For assignment 5, you will be writing a sort for the words in a provided dictionary file of 235,886 entries.
I have already written the code to read in the file (assn5data.txt) as an ArrayList and also store it as an Array of Strings. One of the two structures will probably be useful for the sort that you will write.
I used the ArrayList to run the built-in Java “Collections.sort”.
I use the Array or Strings to run the Selection Sort that I provided.
I am providing the code to do nearly everything except what is asked for below.
For your part:
1.) Change the file name to match the location of the assn5data.txt file on your system
2.) Add another method to perform another sort of your choosing
3.) Call your sort method from the third sort section within the “callSortandTime” method
4.) Comment everything really well
5.) See if you can beat the timing of the other two sorts, but note that it may be very difficult to beat the timing of the built-in Java sort.
The Given Code: https://drive.google.com/open?id=1_5r6NNU0fRDDl7bZNRu1DBWJxDIHEkV5ENCHNvftDRQ
TextFile: https://drive.google.com/open?id=1S1xgv7apoXkd0jabgLyMBh66BTXCQabL2Aa0-pBGaJA
Explanation / Answer
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
const int NUM_NAMES = 30;
void selectionSort(string array[], int NUM_NAMES)
{
int startScan, minIndex;
string minValue;
for(startScan = 0; startScan < (NUM_NAMES -1); startScan++)
{
minIndex = startScan;
minValue = array[startScan];
for(int index = startScan +1; index < NUM_NAMES; index++)
{
if (array[index] < minValue)
{
minValue = array[index];
minIndex = index;
}
}
array[minIndex] = array[startScan];
array[startScan] = minValue;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.