Insertion sort with string array

I am trying to sort a list of names using insertion sort. In my insertion sort function at the bottom of my code i am attempting to pass the integer N into my string array which i know i cannot do. I could do the insertion sort with integers but have no idea how to tell the computer to alphabetize names or how to pass the string array into my loops in the selectionSort function.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>

using namespace std;

void insertionSort(int [], int);
void showArray(string[], int);

int main()
{
	const int SIZE = 5;
	//Array of unsorted names
	string names[SIZE]={"Fred", "Alex", "Diana", "Byron", "Carol"};
	//Show unsorted list of names
	cout << "The unsorted list of names is:";
	showArray(names, SIZE);
	//Sort the list of names using insertion sort
	insertionSort(names, SIZE);
	//Show the list of sorted names
	
	system("pause");
	return 0;
}
void showArray(string array[], int size)
{
	for(int count = 0; count < size; count++)
		cout << array[count]<<" ";
	cout << endl;
}

void insertionSort(string array[], int size)
{
    int N;
	int pivot, temp;
	while(N <= size)
	{
		pivot = array[N];
		temp = pivot;
Last edited on
[code] "Please use code tags" [/code]

¿Why would be any difference?
std::string has defined the operator< that does a lexicographical comparison.
If you want another order relationship (like no-case) do the test with that.

By the way arrays go from 0 to n-1 so
1
2
3
while(N <= size)
{
  pivot = array[N]; //out of bounds 
okay thanks
Topic archived. No new replies allowed.