I am receiving a compile error "'IntNode:trSlot' uses undefined class 'LinkedList1'"
for the code that is in bold below LinkedList1 ptrSlot; . When I remove that it works fine. I tried declaring the classes above but this does not fix the issue?
I am not sure what is wrong?
for the code that is in bold below LinkedList1 ptrSlot; . When I remove that it works fine. I tried declaring the classes above but this does not fix the issue?
I am not sure what is wrong?
Code:
//My example
#include <iostream>
using namespace std;
class IntNode;
class LinkedList1;
class IntNode {
public:
IntNode(){}
IntNode(int theData, IntNode* theLink) : data(theData),link(theLink) {}
IntNode* getLink() const {return link; }
int getData() const {return data; }
void setData(int theData) {data = theData; }
void setLink(IntNode* pointer) {link = pointer; }
//void headInsert(int theData1) { ptrSlot.headInsert(theData1); }
//void remove(int theData1) { ptrSlot.remove(theData1); }
//void deleteHeadNode() { ptrSlot.deleteHeadNode(); }
private:
int data;
IntNode *link;
[B]LinkedList1 ptrSlot;[/B]
};typedef IntNode* IntNodePtr;
class LinkedList1 {
public:
LinkedList1() {head = NULL;}
void headInsert(int theData);
void insert(IntNodePtr afterMe, int theData);
void deleteHeadNode();
void remove(int theData);
void output();
private:
IntNodePtr head;
};
int main() {
char ans;
int tableSize=0;
cout<<"Please enter in the table size: ";
cin >> tableSize;
LinkedList1* first;
first = new LinkedList1[tableSize];
do {
first[0].headInsert(2);
first[0].headInsert(3);
first[0].headInsert(4);
first[0].headInsert(5);
first[0].headInsert(6);
first[0].output();
first[0].deleteHeadNode();
cout<<endl;
first[0].output();
first[0].remove(3);
cout<<endl;
first[0].output();
cout << "Would you like to start over again(y = yes/n = no)? ";
cin >> ans;
} while (ans != 'n');
return 0;
}//end of main
void LinkedList1::headInsert(int theData) {
head = new IntNode(theData, head);
}//end of headInsert
void LinkedList1::insert(IntNodePtr afterMe, int theData) {
afterMe->setLink(new IntNode(theData, afterMe->getLink()));
}//end of insert
void LinkedList1::deleteHeadNode() {
if (head != NULL) {
head = head->getLink();
}//end of if statement
else {
cout<<"You are at the first node already"<<endl;
}//end of else
}//end of deleteHeadNode
void LinkedList1::remove(int theData) {
IntNodePtr before,discard,test;
before = head;
discard = head;
test = head;
int count1 = 0;
int count2 = 0;
int count3 = 0;
if (before == NULL) {
cout<<"List is empty"<<endl;
}
else {
while(discard->getData() != theData && discard->getLink() != NULL) {
count1++;
discard = discard->getLink();
}//end of while loop
int i = count1 - 1;
while (count2 != i) {
before = before->getLink();
count2++;
}//end of while loop
while(test->getLink() != NULL) {
test = test->getLink();
count3++;
}
if(count3 == count1) {
cout<<"Value is not in the list"<<endl;
}
}
before->setLink(discard->getLink());
}//end of remove function
void LinkedList1::output() {
IntNodePtr position = head;
if(position == NULL) {
cout<<"The list is empty"<<endl;
}
else {
while(position != NULL) {
cout<<"The values of the list are "<<position->getData()<<endl;
position = position->getLink();
}//end of while loop
}
}//end of output list