Array template functions - Sorting

I'm writing a program that uses a template function that sorts an array of integers and words.
It asks the user to enter an integer for a number of array elements. A random number generator populates the array with integers and sorts them. It asks the user to enter another integer for a number of array elements. A random number generator fills the array with (double) numbers and sorts them. Then it asks for an integer for a number of array elements with names and sorts them. Here's what I have so far:

My questions are;
1. How do I complete the bubble sort function on line 42?
2. How do I complete the swap function on line 26?
3. Are my parameters correct for all three functions?

The display_array function works. Commenting out anything to do with the other two functions executes the program perfectly. The swap function is yet to be tested.

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
 
#include <iostream>
#include <time.h>
#include <string>
#include <iomanip>
using namespace std;

template <class Item>
void bubble_sort(Item a[], size_t size);

template <class Item>
void swap(Item& a, Item& b);

template <class Item>
void display_array(Item randNum, size_t size);

int main()
{

	int *randNum;
	int a,b;
	int size;




	swap(Item& a, Item& b);  //NOT SURE IF WORKS YET, UNTESTED

	srand((unsigned)time(NULL));
	cout << "How many integers?" << endl;
	cin >> size;
	size = size +1;



	randNum = new int [size];

	 for (int i = 1; i < size; i++)
	 {
		 randNum[i] = 1+ rand() % 10;
	 }

	display_array(randNum, size);



	cout << "\n \n sorted..." << endl;


	
	bubble_sort( a[], size); //ERROR

	//display_array(randNum, size);

	system("pause");
	return 0;

}


//=============================
template <class Item>
void bubble_sort(Item a[], size_t size)
{
	size_t idx, pass;
	for (pass=1; pass<=size; ++pass)
	{
		for (idx=0; idx<=size-2; ++idx)
		{
			if (a[idx] > a[idx+1])
				swap(a[idx], a[idx+1]);
		}
	}
	
}

template <class Item>
void swap(Item& a, Item& b)
{
        Item temp;
        temp = a;
        a = b;
        b = temp;
}


template <class Item>
void display_array(Item randNum, size_t size)
{

	 for ( int j = 1; j < size; j++ )
   {
	  
	 cout  << setw(16) << randNum[ j ];  
	 
   }

}




Here's what I'm expecting it to look like:
 

Here's what I'm expecting it to look like: 

How many integers? 20
8 7 2 12 1
2 5 5 10 18
7 16 18 6 18
1 16 19 19 19

Sorted...
1 1 2 2 5
5 6 7 7 8
10 12 16 16 18
18 18 19 19 19

How many real numbers? 20
143.21 217.14 254.83 191.24 118.33
134.53 106.41 238.39 307.28 207.26
38.93 94.18 291.1 181.82 139.64
292.3 279.3 123.26 71.66 98.56

Sorted...
38.93 71.66 94.18 98.56 106.41
118.33 123.26 134.53 139.64 143.21
181.82 191.24 207.26 217.14 238.39
254.83 279.3 291.1 292.3 307.28

How many words? 5
Enter word 1: Greg
Enter word 2: Nathan
Enter word 3: Billy
Enter word 4: Vicky
Enter word 5: Andy
Greg Nathan Billy Vicky Andy

Sorted...
Andy Billy Greg Nathan Vicky

Press any key to continue . . .

Please, read following article to get source code (and example of using) of the best sorting algorithm:
http://strongcpp.blogspot.ru/2013/04/blog-post_1057.html

Topic archived. No new replies allowed.