Extension of help
Yeah, I'm workin on the same thing (if you find my post from before) and I've got a problem. My program compiles, but then gets an error and I'm trying to find why a loops is happening past where it should be, which then tries to pull information from a pointer when the info doesn't exist. Here's the code the problem may be in. If any explanation is needed, I'll respond when possible.
#ifndef LISTCLASS
#define LISTCLASS
#include
#include
#include"10456904Node.h"
using namespace std;
class List {
Node *fName, *rName; // ptr to first and last Node (by Name)
Node *fAge, *rAge; // ptr to first and last Node (by Age)
int printMode; // print flag (name/age, forward/backward)
public:
List(); // default constructor
~List(); // destructor
List& operator=(const List&); // assignment
List(const List&); // copy constructor
int size(void) const; // size of the list
void insert(string, int); // ordered insert into list
bool remove(string); // remove by Name
bool remove(int); // remove by Age
Node *find(string) const; // find by name
Node *find(int) const; // find by age
// printMode variable indicates how to print
void PrintForward(void); // sets to print forward
void PrintBackward(void); // sets to print backward
void PrintByName(void); // sets to print by name
void PrintByAge(void); // sets to print by age
friend ostream& operator<<(ostream&, const List&);
};
#endif
void List::insert(string s, int num) {
Node *newone = new Node;
newone->Name = s;
newone->Age = num;
Node *tempnum = fAge;
Node *tempname = fName;
if ((tempnum == 0) && (tempname == 0)) {
fName = newone;
rName= newone;
fAge = newone;
rAge = newone;
}
else {
while (tempname) {
if (tempname->Name > s)
tempname = tempname->nName;
else {
(tempname->pName)->nName= newone;
newone->pName = tempname->pName;
tempname->pName = newone;
newone->nName = tempname;
}
}
while (tempnum) {
if (tempnum->Age < num)
tempnum = tempname->nAge;
else {
(tempnum->pAge)->nAge= newone;
newone->pAge = tempnum->pAge;
tempnum->pAge = newone;
newone->nAge = tempnum;
}
}
}
}
ostream& operator<<(ostream& os, const List& a) {
Node *temporary;
switch (a.printMode) {
case 1:
temporary = a.fName;
while (temporary) {
THIS IS WHERE IT IS CALLING IT TWICE
os << temporary->Name << endl;
temporary = temporary->nName;
}
break;
case 2:
temporary = a.fAge;
while (temporary) {
os << temporary->Age << endl;
temporary = temporary->nAge;
}
break;
case 3:
temporary = a.rName;
while (temporary) {
os << temporary->Name << endl;
temporary = temporary->pName;
}
break;
case 4:
temporary = a.rAge;
while (temporary) {
os << temporary->Age << endl;
temporary = temporary->pAge;
}
break;
}
return os;
}
