FIXED - I'm getting a parse error somewhere in this section of code before the else and I can't see it. Please help someone.
NEED HELP HERE -
Okay, I'm apparently getting a parse error somewhere in this code. Any help?
All the errors are listed as "Parse error before '.'" and are happening in the main function at the very end of the code. The first is inside the while statement.
// This is the implementation file for class List
#include <iostream>
#include <fstream>
#include <stddef.h> // to access NULL
#include "List.h"
using namespace std;
typedef NodeType* NodePtr;
struct NodeType
{
ItemType item;
NodePtr next;
};
List::List()
// Post: listPtr is set to NULL.
{
listPtr = NULL;
}
//***********************************************************
List::List(const List& otherList)
// Copy-constructor for List.
{
NodeType* ptr1;
NodeType* ptr2;
if (otherList.listPtr == NULL)
{ listPtr = NULL; }
else
{
listPtr = new NodeType;
listPtr->item = otherList.listPtr->item;
ptr1 = otherList.listPtr->next;
ptr2 = listPtr;
while (ptr1 != NULL)
{ ptr2->next = new NodeType;
ptr2 = ptr2->next;
ptr2->item = ptr1->item;
ptr1 = ptr1->next;
}
ptr2->next = NULL;
}
}
//***********************************************************
bool List::IsThere(ItemType item) const
// Post: If item is in the list IsThere is
// True; False, otherwise.
{
NodeType* location = listPtr;
while (location != NULL)
{ if (item == listPtr->item )
{ return true; } }
return false;
}
//***********************************************************
void List::Insert(ItemType item)
// Pre: item is not already in the list.
// Post: item is the first item in the list.
{
NodeType* location;
if (IsThere(item) == false)
{ location = new NodeType;
location->item = item;
location->next = listPtr;
listPtr = location;
}
}
//***********************************************************
void List::Delete(ItemType item)
// Pre: item is in the list.
// Post: item is no longer in the list.
{
NodeType* location = listPtr;
NodeType* tempLocation;
if (IsThere(item) == true)
{ tempLocation = location->next;
listPtr = listPtr->next;
}
else
{
while (IsThere(item) == true)
{ location = location->next; }
tempLocation = location->next;
location->next = (location->next)->next;
}
delete tempLocation;
}
//***********************************************************
void List::Print() const
// Post: Items on the list are printed on the screen.
{
NodeType* location = listPtr;
while (location != NULL)
{ cout << location->item << endl;
location = location->next; }
}
//***********************************************************
int List::Length() const
// Post: Number of items have been counted; result returned.
{
NodeType* location = listPtr;
int length = 0;
while (location != NULL)
{ location = location->next;
length++; }
return length;
}
//***********************************************************
List::~List()
// Post: All the components are deleted.
{
NodeType* tempPtr;
while (listPtr != NULL)
{
tempPtr = listPtr;
listPtr = listPtr->next;
delete tempPtr;
}
}
int main ()
{
ifstream InData;
InData.open ("int.dat");
while (InData)
{ List.Insert(InData); }
int length = List.Length();
cout << "There are " << length << " many items in this list." << endl;
List.Print();
system ("pause");
return 0;
}