1.

Write a function SORTPOINTS() in C++ to sort an array of structure Game in descending order of Points using Bubble Sort.Note. Assume the following definition of structure Gamestruct Game { long PNo;   //Player Numberchar PName[20];float Points;};Sample Content of the array (before sorting)PNoPName Points103Ritika Kapur3001104John Philip2819101Razia Abbas3451105Tarun Kumar2971Sample Content of the array (after sorting)RollNoName Score101Razia Abbas3451103Ritika Kapur3001105Tarun Kumar2971104John Philip2819

Answer»

void SORTPOINTS(Game G[ ], int N)

{

Game Temp;

for (int I=0; I<N-1;I++)

for (int J=0;J<N-I-1;J++)

if (G[J].Points <G[J+1].Points)

{

Temp = G[J];

G[J] = G[J+1];

G[J+1] = Temp;

}

}



Discussion

No Comment Found

Related InterviewSolutions