How can i correct the following code, i get the errors down below

interface.h

using namespace std;

struct DataType {
int key;
string name;
};

struct Node {
DataType data; // the actual data goes in here
Node *link; // link to the next node in the linked list

};
class LList {

int count;
Node *rear;
Node *top;

public:
LList();
~LList();

bool InsertLList(DataType data);
bool SearchLList(DataType data);
bool RemoveItem (int key);

void freeLLmemory();
void displayLList();

};
#include "implement.h"

implement.h

LList::LList()
{
count = 0;
rear = NULL;
top = NULL;
}

LList::~LList()
{
freeLLMemory();
count = 0;
top = rear = NULL;

}

bool LList::InsertLList(DataType data)
{
Node *temp;

temp = new(nothrow)Node; // allocate space for a new
// node and store its address in temp

temp->data = data; // copy the data over into
// the new node
temp->link = NULL; // and this new node is
// not pointing at any other node

// is the linked list empty?
if(top == NULL) {
// if so this new node is the first node into the linked list
top = temp;
rear = temp;
}
else
{ // else already
// have some nodes in the linked list
rear->link = temp; // the last node; link
// it to the new node
rear = temp; // now make this new
// node the last node
}

count++; // shows that we have added one more node

}

// function to look for a node; given a key, search for it in the linked list
// and return the node found in dataOut

bool LList::SearchLList(Node &nodeOut,int key)
{
Node *temp;
bool retFlag= false; // determines the
//result of the search

temp = top;
while(temp != NULL) { // start from the beginning node in the
// linked list
if(temp->data.key == key) {
retFlag = true;
nodeOut = temp;
break; // break
//out of the while loop
}
temp = temp->link; // let us look at the
// next item
}

return retFlag;
}

// function to remove a node from the list; we search for a node whose key
// value matches the keyIn

bool LList::RemoveItem(int key)
{
Node *nodeOut; // will contain address of
// the node to remove

bool retFlag;
char resp;

retFlag = SearchLList(nodeOut,key);
if(retFlag == true) { // we were able to find the node
cout << "Key: " << nodeOut->key << " Name: " << nodeOut->name
<< "\n";
cout << "\n\nDo you really want to remove this node? (Y/N): ";
cin >> resp;
//--- delete node -----

}


// free the memory held up by the linked list

void LList::freeLLMemory()
{

Node *temp = top; // gets the address of the first item on
// the list

while(top != NULL)
{
temp = temp->link;
delete top;
top = temp;
}
}

// function to display the items on the list
bool LList::displayLList();
{

Node *temp = top; // gets the address of the first item on
// the list
if (temp == NULL)
cout << "\nThe Linked List is empty...\n";
else {
while(temp!= NULL) {
cout << "Key: " << temp->key << " Name: " << temp->name
<< "\n";
temp = temp->link;
}
cout << endl;
}
}
void main()
// main.cpp


#include <iostream>
#include <string>
#include <new>
#include "interface.h"


void main()
{
LList myLList();

DataType data;

data.key = 100;
data.name = "Nkhata";

myLList.InsertLList(data);
myLList.displayLList();
myLList.SearchLList(data);
myLList.RemoveItem(key);
myLList.freeLLmemory();
}
errors
: error C3861: 'freeLLMemory': identifier not found
: error C2511: 'bool LList::SearchLList(Node &,int)' : overloaded member function not found in 'LList'
: see declaration of 'LList'
: error C2660: 'LList::SearchLList' : function does not take 2 arguments
: error C2039: 'key' : is not a member of 'Node'
: see declaration of 'Node'
: error C2039: 'name' : is not a member of 'Node'
: see declaration of 'Node'
: error C2039: 'freeLLMemory' : is not a member of 'LList'
: see declaration of 'LList'
: error C2601: 'freeLLMemory' : local function definitions are illegal
.h(77): this line contains a '{' which has not yet been matched
: error C2761: 'void LList::displayLList(void)' : member function redeclaration not allowed
: error C2039: 'key' : is not a member of 'Node'
h(10) : see declaration of 'Node'
: error C2039: 'name' : is not a member of 'Node'
: error C2601: 'main' : local function definitions are illegal
h(77): this line contains a '{' which has not yet been matched
: fatal error C1075: end of file found before the left brace '{

Last edited on
post the errors messages so we can help faster
@ Blessman11(204) i have posted the errors
The listed functions are either misstyped (like freeLLMemory) or have the wrong paramter (like SearchLList(Node &nodeOut,int key) <-> SearchLList(DataType data);)
Topic archived. No new replies allowed.