cs162/assignments/assignment1/magic.cpp
/*********************************************************************
 * ** Function: sr_sort
 * ** Description: This function sorts the spellbooks based on their average success rate
 * ** Parameters: wizard *wiz, int wiz_index, spellbook *spells, int num_books
 * ** Pre-Conditions: user has chosen to sort spellbooks by their average success rate
 * ** Post-Conditions: spells are sorted by average success rate and user is prompted to print/save the outcome
 * *********************************************************************/
sr_sort
Description: This function sorts the spellbooks based on their average success rate
Parameters: wizard *wiz, int wiz_index, spellbook *spells, int num_books
Pre-Conditions: user has chosen to sort spellbooks by their average success rate
Post-Conditions: spells are sorted by average success rate and user is prompted to print/save the outcome
sr_sort Description : This function sorts the spellbooks based on their average success rate Parameters : wizard * wiz int wiz_index spellbook * spells int num_books Pre - Conditions : user has chosen to sort spellbooks by their average success rate Post - Conditions : spells are sorted by average success rate and user is prompted to print / save the outcome
void sr_sort(wizard *wiz, int wiz_index, spellbook *spells, int num_books) {
	spellbook *sr = spells;
	for(int i = 0; i < num_books; i++) {
		for(int j = 0; j < num_books - 1; j++) {
			if(sr[j].avg_success_rate < sr[j+1].avg_success_rate) {
				spellbook temp = sr[j];
				sr[j] = sr[j+1];
				sr[j+1] = temp;
			}
		}
	}
	print_or_file_sr(sr, num_books);
}
void sr_sort ( wizard * wiz , int wiz_index , spellbook * spells , int num_books ) { spellbook * sr = spells ; for ( int i = 0 ; i < num_books ; i ++ ) { for ( int j = 0 ; j < num_books - 1 ; j ++ ) { if ( sr [ j ] . avg_success_rate < sr [ j + 1 ] . avg_success_rate ) { spellbook temp = sr [ j ] ; sr [ j ] = sr [ j + 1 ] ; sr [ j + 1 ] = temp ; } } } print_or_file_sr ( sr , num_books ) ; }
** Function: sr_sort
 ** Description: This function sorts the spellbooks based on their average success rate
 ** Parameters: wizard *wiz, int wiz_index, spellbook *spells, int num_books
 ** Pre-Conditions: user has chosen to sort spellbooks by their average success rate
 ** Post-Conditions: spells are sorted by average success rate and user is prompted to print/save the outcome
** Function : sr_sort ** Description : This function sorts the spellbooks based on their average success rate ** Parameters : wizard * wiz int wiz_index spellbook * spells int num_books ** Pre - Conditions : user has chosen to sort spellbooks by their average success rate ** Post - Conditions : spells are sorted by average success rate and user is prompted to print / save the outcome