try this code
and repost to tell us if it works like you expect , please
IMPORTANT NOTICE: operator new() return a pointer , you should deal with it in this way
Code:
#include <iostream.h>
#include <conio.h>
class ArrayBub
{
public:
ArrayBub(int);
void insert(double);
void display();
void bubbleSort();
void swap(int, int);
private:
double* a ;
int nElems;
};
ArrayBub::ArrayBub(int max)
{
a = new double[max];
nElems = 0;
}
void ArrayBub::insert(double value)
{
a[nElems] = value;
nElems++;
}
void ArrayBub::display()
{
for(int j=0; j<nElems; j++)
{
cout << *(a)<< " ";
a++;
}
cout<<endl;
}
void ArrayBub::bubbleSort()
{
int out, in;
for (out=nElems-1; out>1; out--)
for(in=0; in<out; in++)
if(a[in]>a[in+1])
swap(in, in+1);
}
void ArrayBub::swap(int one, int two)
{
double temp = a[one];
a[one] = a[two];
a[two] = temp;
}
int main()
{
int maxSize = 100;
ArrayBub *arr;
arr = new ArrayBub(maxSize);
arr->insert(2213);
arr->insert(33);
arr->insert(2);
arr->insert(58);
arr->insert(987);
arr->insert(11);
arr->insert(47);
arr->insert(7);
arr->insert(223);
arr->insert(26);
arr->insert(58);
arr->insert(7);
arr->display();
arr->bubbleSort();
arr->display();
getche();
return 0;
}
i hope it helps
pointer