Here is a link to the actual assignment http://bluehawk.monmouth.edu/~rscherl/Classes/CS503/hw2.pdf.
At this point I am able to build the linked list from a users input string as well as display that list. Here is the code that I have up to this point. I have two classes a Node class and a List class, I have the implementation files for those classes as well as a main driver program. I guess how do I test conditions for example: within the function buildList if(myString == '(') loop through myString adding elements to the list until you hit a ')' how do I do that?
// List.h: interface for the CList class.
//
//////////////////////////////////////////////////////////////////////
#ifndef LIST_H
#define LIST_H
#include <string>
#include <iostream>
#include "Node.h"
class CList
{
public:
CList();
~CList();
CList(const CList & origList);
void buildList(char *myString);
void insertNode(int);
void deleteNode(int);
void appendNode(int);
void displayList(void);
private:
CNode * first;
CNode * rest;
};
#endif
--------------------------------------------------------------------------
// Node.h: interface for the CNode class.
//
//////////////////////////////////////////////////////////////////////
#ifndef NODE_H
#define NODE_H
class CNode
{
public:
CNode();
~CNode();
int value;
CNode *next;
};
#endif
--------------------------------------------------------------------------
// Node.cpp: implementation of the CNode class.
//
//////////////////////////////////////////////////////////////////////
#include "Node.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CNode::CNode()
{
}
CNode::~CNode()
{
}
--------------------------------------------------------------------------
// List.cpp: implementation of the CList class.
//
//////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include "List.h"
using namespace std;
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CList::CList()
{
first = NULL;
}
CList::~CList()
{
}
CList::CList(const CList & origList)
{
}
void CList::buildList(char *myString)
{
int num = 0;
int len = strlen(myString);
for(int i = 0; i < len ; i++)
{
num = myString[i];
insertNode(num);
}
}
void CList::insertNode(int num)
{
CNode *newNode, *nodePtr;
//Allocate a new node & store num
newNode = new CNode;
newNode ->value = num;
newNode ->next = NULL;
//If there are no nodes in the list
//make newNode the first node
if(!first)
first = newNode;
//Otherwise, insert newNode at end
else
{
//Initialize nodePtr to head of list
nodePtr = first;
//Find the last node in the list
while (nodePtr->next!= NULL)
{
nodePtr = nodePtr -> next;
}
//Insert newNode as the last node
nodePtr -> next = newNode;
}
}
void CList::displayList()
{
CNode *ptr;
ptr = first;
while (ptr != NULL)
{
cout<<(char)ptr->value;
ptr = ptr->next;
}
cout<<endl;
}
--------------------------------------------------------------------------
// Lists.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <string>
#include "Node.h"
#include "List.h"
using namespace std;
int main()
{
CList L1;
char list[1024];
cout << "Please enter an list or type exit conclude this program!" << endl;
cin.getline(list, 1024);
L1.buildList(list);
L1.displayList();
return 0;
}