I have been given an assignment to add to an already given program. I have been told to add the following: "isEmptyList, print, destroyList, deleteNode and insertNode. What I was given is below. I have been adding to the program but I come up with errors. I am not sure where or what and how to add these functions. Please help.
createNodeExample.txt
// createExam.cpp : main project file.
#include "stdafx.h"
#include <cassert>
#include <cstdlib>
#include <iostream>
using namespace std;
using namespace System;
//R. C. Dawkins
// September 26, 2014
// Example of Creating a linked list of numbers until -99 is entered.
class nodeType
{
private:
int info;
nodeType *link;
public:
void create()
{
nodeType *headPtr, *tailPtr, *newNodePtr;
headPtr = NULL;
tailPtr = NULL;
int num;
cout << "Enter a list of integers. To end enter -99" << endl << "number:";
cin >> num;
headPtr = NULL;
tailPtr = NULL;
while(num != -99)
{
newNodePtr = new nodeType;
assert(newNodePtr != NULL); // Checks to see if memory was allocated
newNodePtr->info = num;
newNodePtr->link = NULL;
if( headPtr == NULL)
{
headPtr = newNodePtr;
tailPtr = newNodePtr;
}
else
{
tailPtr->link = newNodePtr;
tailPtr = newNodePtr;
}
cout << "Enter Number: ";
cin >> num;
}
}
};
int main()
{
cout << "Example of creating a linked list" << endl;
nodeType myNode;
myNode.create();
system("pause");
return 0;
}
// createExam.cpp : main project file.
//#include "stdafx.h"
#include <cassert>
#include <cstdlib>
#include <iostream>
usingnamespace std;
usingnamespace System; // error C2871: 'System' : a namespace with this name does not exist
//R. C. Dawkins
// September 26, 2014
// Example of Creating a linked list of numbers until -99 is entered.
class nodeType
{
private:
int info;
nodeType *link;
public:
void create()
{
nodeType *headPtr, *tailPtr, *newNodePtr;
headPtr = NULL;
tailPtr = NULL;
int num;
cout << "Enter a list of integers. To end enter -99" << endl << "number:";
cin >> num;
headPtr = NULL;
tailPtr = NULL;
while(num != -99)
{
newNodePtr = new nodeType;
assert(newNodePtr != NULL); // Checks to see if memory was allocated
newNodePtr->info = num;
newNodePtr->link = NULL;
if( headPtr == NULL)
{
headPtr = newNodePtr;
tailPtr = newNodePtr;
}
else
{
tailPtr->link = newNodePtr;
tailPtr = newNodePtr;
}
cout << "Enter Number: ";
cin >> num;
}
}
};
int main()
{
cout << "Example of creating a linked list" << endl;
nodeType myNode;
myNode.create();
system("pause");
return 0;
}
Solution? Remove that line, you shouldn't be using namespace, it's bad practice and isn't normally used in production code. std is the C++ standard library namespace and System is the .Net namespace, which you won't be using at all, so shouldn't be there.
I have been told to add the following: isEmptyList, print, destroyList, deleteNode and insertNode. I am not sure where or what and how to add these functions. Please help.
The functions are members of the class, so they're added as show, but you need to implement them yourself.