0% found this document useful (0 votes)
23 views1 page

C++ Bubble Sort for Game Points

The document provides a C++ function named SORTPOINTS() that sorts an array of structures representing players in a game based on their points in descending order using the bubble sort algorithm. The structure 'game' contains three fields: player number (pno), player name (pname), and points. The sorting is achieved through nested loops that compare and swap elements based on their points.

Uploaded by

Sneha Malik
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views1 page

C++ Bubble Sort for Game Points

The document provides a C++ function named SORTPOINTS() that sorts an array of structures representing players in a game based on their points in descending order using the bubble sort algorithm. The structure 'game' contains three fields: player number (pno), player name (pname), and points. The sorting is achieved through nested loops that compare and swap elements based on their points.

Uploaded by

Sneha Malik
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

write a function SORTPOINTS() in c++ to array of structure game in

descending order of points using bubble sort. [CBSE 2009]


struct game
{
long pno; //player number
char pname[20; //player name
long points;
};

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;
}
}
}
}

You might also like