Apr 6, 2012 at 5:07am UTC
I am stuck on how to approach this assignment. I need to create a template class that incorporates The STL list into a sorted_bag. Below is most of what I have so far.
#include <cstdlib>
#include <iostream>
#include <list>
using namespace std;
template <class Type>
class sorted_bag
{
public:
sorted_bag<Type> operator +=(const sorted_bag<Type>& b1,
const sorted_bag<Type>& b2);
// Constructors & Destructor
sorted_bag();
sorted_bag(const sorted_bag<Type>& x);
~sorted_bag();
// Modification Member Functions
void insert (const Type& entry);
bool remove(const Type& target);
void operator +=(const sorted_bag& addend);
void operator =(sorted_bag& x);
// Const Member Functions
size_type count(const Type& target) const;
size_type size() const
{
return node_number;
}
friend ostream& operator<<(ostream& os, sorted_bag<Type>& source);
private:
list<Type> *head_ptr;
int node_number;
};
template <class Type>
sorted_bag<Type>::sorted_bag()
{
head_ptr = NULL;
node_number = 0;
}
template <class Type>
sorted_bag<Type>::sorted_bag(const sorted_bag<Type>& x)
{
}
template <class Type>
sorted_bag<Type>::~sorted_bag()
{
node<Type> *remove_ptr;
remove_ptr = head_ptr;
node_number = 0;
}
template <class Type>
sorted_bag<Type> operator +=(const sorted_bag<Type>& b1,
const sorted_bag<Type>& b2)
{
sorted_bag<Type> answer;
answer += b1;
answer += b2;
return answer;
}
Apr 6, 2012 at 5:08am UTC
I need help with an approach to using iterators with this as well!! I feel in over my head.