Possible Duplicate:
singly linked chain printing c++
How can I get my void display function to display the array found in my Set function; also how would I reference that display function in my driver file?
Thanks.
Relevant files are below
header file
#ifndef SET_
#define SET_
using namespace std;
#include <iostream>
class Set
{
private:
unsigned Cap; // Current capacity of the set
unsigned Num; // Current count of items in the set
int * Pool; // Pointer to array holding the items
public:
// Return information about the set
//
bool is_empty() const { return Num == 0; }
unsigned size() const { return Num; }
unsigned capacity() const { return Cap; }
// Initialize the set to empty
//
Set()
{
Cap = Num = 0;
Pool = NULL;
}
// De-initialize the set
//
~Set();
// Initialize the set using an existing set
//
Set( const Set& );
// Assign into the set from another set
//
Set& operator=( const Set& );
// Test for presence of a specified item in the set
//
bool is_present( int ) const;
// Remove a specified item from the set, if possible
//
bool remove( int );
// Insert a specified item into the set, if possible
//
bool insert( int );
// Display the set
//
void display( ostream& ) const;
// Produce the union of two sets
//
friend Set operator+( const Set&, const Set& );
// Produce the intersection of two sets
//
friend Set operator^( const Set&, const Set& );
};
#endif
my implementation file
using namespace std;
#include <iostream>
#include "/user/cse232/Projects/project07.set.h"
void bubbleSort(int arr[], int n)
{
bool swapped = true;
int j = 0;
int tmp;
while(swapped)
{
j++;
for(int i = 0; i < n-j; i++)
{
if(arr[i] > arr[i+1])
{
tmp = arr[i];
arr[i] = arr[i+1];
arr[i+1] = tmp;
swapped = true;
}
}
}
}
Set::~Set()
{
Cap = 0;
Num = 0;
delete [] Pool;
Pool = NULL;
}
/*bool Set::is_present(int X) const
{
bool Flag = false;
while(unsigned Z=0;Z<=Num;Z++)
{
if(Pool[Z] = X)
{
Flag = true;
}
}
return Flag;
}*/
bool Set::insert(int X)
{
bool Flag = false;
if(Num == Cap)
{
//reallocate memory
const unsigned Inc = 3;
try
{
int * temp = new int[Cap+Inc];
for(unsigned J=0; J<Num; J++)
{
temp[J] = Pool[J];
}
delete [] Pool;
Pool = temp;
}
catch(std::bad_alloc)
{
cerr << "\n*** UNABLE TO INCREASE CAPACITY ***\n\n";
}
}
if(Num < Cap)
{
//insert stuff
Pool[Num+1] = X;
Num++;
bubbleSort(Pool,Num);
Flag = true;
}
return Flag;
}
void display(ostream &out) const
{
//print the array
}