0

Hi to all, I am new to this C++ world

I have kind of a quick question. I need to do a modified selection sort that can handle characters. I know how to do one but only with integers (see code below). Any help or suggestion as to how I should go about it is greatly appriciated. : )
//function selection_sort...

void selection_sort (int array[], int elements)
{	
	int start_scan, my_index, my_value;
	
	for (start_scan = 0; start_scan < (elements - 1); start_scan++)
	{
		my_index = start_scan; 
		my_value = array[start_scan];

		for (int index = start_scan + 1; index < elements; index++)
		{

			if (array[index] < my_value)
			{
				my_value = array[index];
				my_index = index;
			}
		}	
		array[my_index] = array[start_scan];  //swap the elements
		array[start_scan] = my_value;
	}		
}
2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Ancient Dragon
0

Just replace int array[] with std::string array[] and int my_value with std::string my_value , the rest of that will not change.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.