//CSet02.cpp
//Date 04/23/2003
//Author: AOU
/*
Added the following functions:
CNode(char ch);
int get(void);
void set(int x);
friend ostream & operator << (ostream & tom, CNode node);
bool operator == (CNode node);
*/
#include <iostream.h>
#include <stdlib.h>
const int UNDEFINED = -99;
const int MAX_VALUE = 99;
class CNode
{
private:
int m_info;
CNode *m_next;
public:
CNode(void);
CNode(int x);
void display(void) const;
CNode(char ch);
int get(void);
void set(int x);
friend ostream & operator << (ostream & tom, CNode node);
bool operator == (CNode node);
};
class CSet
{
private:
CNode *m_first;
int m_n;
public:
CSet(void);
CSet(char ch);
CSet(CNode n);
void insert(int x);
CNode* seqSearch(int x);
void display(void) const;
void sortBubble(void);
void sortSelection(void);
void sortInsertion(void);
};
void main(void)
{
CNode myNode;
myNode.display();
cout << endl;
CNode myNode1(55);
myNode1.display();
cout << endl;
CNode myNode2('r');
myNode2.display();
cout << endl;
cout << "info=" << myNode2.get() << endl;
myNode2.set(32);
cout << "info=" << myNode2.get() << endl;
cout << myNode2 << endl;
if (myNode1 == myNode2)
cout << "myNode1 is equal to myNode2\n";
else
cout << "myNode1 is NOT equal to myNode2\n";
myNode1 = myNode2;
if (myNode1 == myNode2)
cout << "myNode1 is equal to myNode2\n";
else
cout << "myNode1 is NOT equal to myNode2\n";
}
bool CNode::operator == (CNode node)
{
return (this->m_info == node.m_info);
}
ostream & operator << (ostream & tom, CNode node)
{
tom << node.m_info;
return tom;
}
void CNode::set(int x)
{
this->m_info = x;
}
int CNode::get(void)
{
return this->m_info;
}
CNode::CNode(char ch)
{
if ('r' == ch)
this->m_info = rand()%(MAX_VALUE+1);
else
this->m_info = UNDEFINED;
}
CNode::CNode(void)
{
this->m_info = UNDEFINED;
this->m_next = NULL;
}
void CNode::display(void) const
{
cout << this->m_info;
}
CNode::CNode(int x)
{
this->m_info = x;
this->m_next = 0;
}
/*
SAMPLE RUN:
-99
55
41
info=41
info=32
32
myNode1 is NOT equal to myNode2
myNode1 is equal to myNode2
Press any key to continue
*/
|