Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions Icon

Related questions

Question

Please make a searching and sorting algorithm for the program below. In the photos I have provide what a sorting and searching algorithm code looks like

 

java program is below

 

 

// method to search a String array for a name
public static int findName (String nameToFind, String array[])
f
int place= -1; // place is negative if not found
// loop through array
for (int i = 0; i < array.length; i++)
{
//check if name to find is equal to current array element.
if (nameToFind.equalsIgnoreCase (array [i]) == true)
{
place i // store location of name.
}
return place; // return location.
}// end findName method
String findMe; // string to store name to find
findMe JOptionPane.showInput Dialog ("Enter player to search");
int loc; // variable to store location
loc findName (findMe, playerNames); // call findName method with array and name.
if (loc < 0) // negative location means not found
{
JOptionPane.showMessageDialog (null, findMe + " not found");
}
else
(
JOptionPane.showMessageDialog (null, playerNames [loc] + " has " + playerGoals [loc] +
goals");
expand button
Transcribed Image Text:// method to search a String array for a name public static int findName (String nameToFind, String array[]) f int place= -1; // place is negative if not found // loop through array for (int i = 0; i < array.length; i++) { //check if name to find is equal to current array element. if (nameToFind.equalsIgnoreCase (array [i]) == true) { place i // store location of name. } return place; // return location. }// end findName method String findMe; // string to store name to find findMe JOptionPane.showInput Dialog ("Enter player to search"); int loc; // variable to store location loc findName (findMe, playerNames); // call findName method with array and name. if (loc < 0) // negative location means not found { JOptionPane.showMessageDialog (null, findMe + " not found"); } else ( JOptionPane.showMessageDialog (null, playerNames [loc] + " has " + playerGoals [loc] + goals");
// sort the arrays by increasing goals
// loop through the whole array
for (int i = 0; i < playerNames.length; i++)
(
//loop through to compare two elements next to
each other
for (int j = 0; j < playerNames.length 1; j++)
{
//compare one element to the next
if (playerGoals [j] > playerGoals [j+ 1])
{
// swap goals if not in increasing order
int tempGoals = playerGoals [j];
playerGoals [j] playerGoals [j+1];
playerGoals [j+1] = tempGoals;
// swap names to keep lists correct.
String tempNames playerNames [j];
playerNames [j] playerNames [j+1];
playerNames [j+1] = tempNames;
} // end if
}// end for j
}// end for i
expand button
Transcribed Image Text:// sort the arrays by increasing goals // loop through the whole array for (int i = 0; i < playerNames.length; i++) ( //loop through to compare two elements next to each other for (int j = 0; j < playerNames.length 1; j++) { //compare one element to the next if (playerGoals [j] > playerGoals [j+ 1]) { // swap goals if not in increasing order int tempGoals = playerGoals [j]; playerGoals [j] playerGoals [j+1]; playerGoals [j+1] = tempGoals; // swap names to keep lists correct. String tempNames playerNames [j]; playerNames [j] playerNames [j+1]; playerNames [j+1] = tempNames; } // end if }// end for j }// end for i
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Similar questions
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY