MENU
Question -

Write a function SORTSCORE() in C++ to sort an array of structure IPL in descending order of score using selection sort.
Note : Assume the following definition of structure IPL:
struct IPL:

 {
 int Score;
 char Teamname[20];
 } ;



Answer -

void SORTSCORE (IPL a[] , int n)
{ int largest;
IPL temp;
for ( int K = 0; K
{ largest = K;
for ( int j = K+1; j< n; j++) { if ( a[j].score > a[largest]. score)
{ largest = j;
}
}
temp = a[K];
a[K] = a[largest];
a [largest] = temp;
}
}

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
×