Program Help using a template
Nov 5, 2014 at 6:08pm UTC
I need to figure out how to get this program to allow you to input integers and characters. Right now it only allows integers. I have the char commented out. I have to use templates. Help will be much appreciated.
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
#include <iostream>
using namespace std;
void sort(int n);
void swap(int *p1, int *p2);
//void swap(char *p1, char *p2);
//char a[10];
int a[10];
int main()
{
int i;
for (i=0;i < 10; i++)
{
cout << "Enter array element #" << i+1 << ": " ;
cin >> a[i];
}
sort(10);
cout << "Here is the array sorted: " << endl;
for (i=0; i<10; i++)
{
cout << a[i] << " " ;
}
cout << endl;
return 0;
}
/*
Bubble Sort routine
*/
void sort( int n)
{
int i, j, low;
for (i=0; i<10; i++)
{
low = i;
for (j=i+1; j<n; j++)
if (a[j] < a[low])
low = j;
if (i != low)
swap (&a[i], &a[low]);
}
}
void swap(int * p1, int * p2)
//void swap(char* p1, char*p2)
{
//char temp;
int temp;
temp =*p1;
*p1 = *p2;
*p2 = temp;
}
Topic archived. No new replies allowed.