Example #1
0
void sort_max(My_vec& vec)
{
	if (vec.is_empty()){  cout<< "error, vector is empty"<<endl;}
	else
	{
		My_vec temp =vec;
		
		for(int i = vec.get_size(); i>0; i--)
		{
				int rank = find_max_index(vec, i);
				char tempt = vec[rank];
				temp.replace_at_rank(i-1,tempt);
				vec.remove_at_rank(rank);

		}
		vec =temp;
	}
};
Example #2
0
int find_max_index(const My_vec& vec, int n)
{
	if (vec.is_empty() || n<0 ){  cout<< "error, rank is outside range of vector"<<endl; return NULL;}
	else
	{
		int count;
		if (vec.get_size() > (n-1)) count = (n-1);
		else count = vec.get_size()-1;
		int rank=0;
		for (int i=0; i<count; ++i)
		{
			if (vec.elem_at_rank(i+1) < vec.elem_at_rank(rank)) {rank =rank;}
			else {rank = i+1;}	
			
		}
		return (rank);
	}
};