Hi, I am back again and need some more help please. I have to write a template that performs a bubble sort, and then I need to write an overload function template prinArray. I have the first part (well with a double, couldn't make the float work) but I'm lost on the second part
Here is the assignment:
Write a function template bubbleSort , then write a driver program that inputs, sorts and outputs an int array and a float array.Write an overload function template printArray so that it takes an array structure, int size and two additional integer arguments, namely int lowSubscript and int highSubscript. A call to this function will print only the designated portion of the array. Validate lowSubscript and highSubscript; if either is out-of-range or if highSubscript is less than or equal to lowSubscript the function returns zero.
I'm just looking for a start with the second part, and a little understanding, for some reason I've drawn a blank. It's probably because I don't understand overloading very well.
Here is what I have:
#pragma once
#include <iostream>
using namespace System;
using namespace std;
template <class X> void bubble(X *data, int size)
{
register int a, b;
X t;
for(a=1; a < size; a++)
for(b=size-1; b >= a; b--)
if(data[b-1] > data[b])
{
t = data[b-1];
data[b-1] = data[b];
data[b] = t;
}
}
//template <class X> void print(X *data, int size, int lowScript, int highScript)
// MyBubbleSort.cpp : main project file.
#include "stdafx.h"
#include "bubble.h"
#include <iostream>
using namespace System;
using namespace std;
int main(array<System::String ^> ^args)
{
int j;
int Iarray[] = {7, 5, 4, 3, 9, 8, 6};
double Darray[] = {4.3, 2.5, -0.9, 10.2, 3.0};
bubble(Iarray, 7);
bubble(Darray, 5);
cout << "Here is a sorted Int Array:"<<endl;
for(j=0; j<7; j++)
cout << Iarray[j] << ' ';
cout << endl;
cout << endl;
cout << "Here is a sorted double Array:"<<endl;
for(j=0; j<5; j++)
cout << Darray[j] << ' ';
cout << endl;
return 0;
}