Bubble sort this for me, from highest scorer to lowest Highest should be Allen I
ID: 3557741 • Letter: B
Question
Bubble sort this for me, from highest scorer to lowest
Highest should be Allen Iverson
Lowest should be Steve Nash
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
const int NUM_PLAYERS=11;
const int NAME_SIZE=32;
const int PLAYER_POSITION=8;
?
?
int displayNames(char[]);
void sort(char player[NUM_PLAYERS][NAME_SIZE],double*);
int main()
{
char player[NUM_PLAYERS][NAME_SIZE]={"Allen Iverson","Tim Duncan","Tim Duncan","Kevin Garnett","Steve Nash","Steve Nash","Dirk Nowitzki","Lebron James","Lebron James","Derrick Rose"};
double ppg[11]={31.1,25.5,23.3,24.2,15.5,18.8,24.6,28.3,28.4,29.7};
?
?
?
?
?
for(int i=0; i<10; i++)
{
ppg[i];
for(int j=0; j<NAME_SIZE; j++)
{
player[i][j];
cout<<player[i][j];
}
cout<<ppg[i];
cout<<endl;
}
?
system("pause");
return 0;
}
void sort(char player[NUM_PLAYERS][NAME_SIZE],double*ppg)
{int temp=0;
for(int i=0; i<NUM_PLAYERS; i++)
{
ppg[i];
for(int j=0; j<NAME_SIZE; j++)
if(ppg[i]>ppg[i+1])
{
temp=ppg[i];
ppg[i]=ppg[i+1];
ppg[i+1]=temp;
char tempChar=player[i][j]
?
?
}
?
?
}
?
?
?
}
Explanation / Answer
void sort(char player[NUM_PLAYERS][NAME_SIZE],double*ppg)
{
int temp=0;
for(int i=0; i<NUM_PLAYERS; i++)
{
for(int j=0; j<i; j++)
{
if(ppg[j]>ppg[j+1])
{
temp=ppg[j];
ppg[j]=ppg[j+1];
ppg[j+1]=temp;
char temp = 0;
for(int k = 0; k < 32; ++i)
{
temp = player[j][k];
player[j][k] = player[j + 1][k];
plater[j+1][k] = temp;
}
}
}
}
}
This code should work however i could not check it.Plz ask if anydoubt or it does not work as intented
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.