cs162/assignments/assignment1/magic.cpp
/*********************************************************************
 * ** Function: page_sort
 * ** Description: This function sorts the spellbooks in order of number of pages
 * ** Parameters: wizard *wiz, int wiz_index, spellbook *spells, int num_books
 * ** Pre-Conditions: user selected to sort the spellbooks by page number
 * ** Post-Conditions: user is prompted to print sorted spellbooks to screen or to save them
 * *********************************************************************/
page_sort
Description: This function sorts the spellbooks in order of number of pages
Parameters: wizard *wiz, int wiz_index, spellbook *spells, int num_books
Pre-Conditions: user selected to sort the spellbooks by page number
Post-Conditions: user is prompted to print sorted spellbooks to screen or to save them
page_sort Description : This function sorts the spellbooks in order of number of pages Parameters : wizard * wiz int wiz_index spellbook * spells int num_books Pre - Conditions : user selected to sort the spellbooks by page number Post - Conditions : user is prompted to print sorted spellbooks to screen or to save them
void page_sort(wizard *wiz, int wiz_index, spellbook *spells, int num_books) {
	spellbook *page = spells;
	for(int i = 0; i < num_books; i++) {
		for(int j = 0; j < num_books - 1; j++) {
			if(page[j].num_pages > page[j+1].num_pages) {
				spellbook temp = page[j];
				page[j] = page[j+1];
				page[j+1] = temp;
			}
		}
	}
	print_or_file_page(page, num_books);
}
void page_sort ( wizard * wiz , int wiz_index , spellbook * spells , int num_books ) { spellbook * page = spells ; for ( int i = 0 ; i < num_books ; i ++ ) { for ( int j = 0 ; j < num_books - 1 ; j ++ ) { if ( page [ j ] . num_pages > page [ j + 1 ] . num_pages ) { spellbook temp = page [ j ] ; page [ j ] = page [ j + 1 ] ; page [ j + 1 ] = temp ; } } } print_or_file_page ( page , num_books ) ; }
** Function: page_sort
 ** Description: This function sorts the spellbooks in order of number of pages
 ** Parameters: wizard *wiz, int wiz_index, spellbook *spells, int num_books
 ** Pre-Conditions: user selected to sort the spellbooks by page number
 ** Post-Conditions: user is prompted to print sorted spellbooks to screen or to save them
** Function : page_sort ** Description : This function sorts the spellbooks in order of number of pages ** Parameters : wizard * wiz int wiz_index spellbook * spells int num_books ** Pre - Conditions : user selected to sort the spellbooks by page number ** Post - Conditions : user is prompted to print sorted spellbooks to screen or to save them