I have been tasked to update code provided to me to what in class is called the "Ultimate Linked List". I am having some issues with removing errors in the code after adding what I think is necessary to complete it. I have listed the code that I have edited into this text block.
Commented out code is the code that I am replacing, the replacement code is directly below the blocked portion with the same name.
I have attached all the code in a file as well, due to the way our class works we create Projects in DevC++ rather than everything being held in a single source file. Sorry for the inconvenience.
Any assistance with fixing the compile-time errors is very appreciated!
LLSList.cpp
LLSList.h
main.cpp
Note: This is an assignment for a class I am currently taking.
Code:
// Implementation file for List
#include <iostream>
#include "LLSList.h"
struct LNode {
int item;
LNode* next;
LNode* prev;
};
LLSList::LLSList() {
ListStart=ListEnd;
ListEnd=NULL;
}
LLSList::~LLSList() {
LNode* tempPtr;
while (ListStart != NULL) {
tempPtr = ListStart;
ListStart = ListStart->next;
delete tempPtr;
}
}
bool LLSList::IsFull() const {
LNode* testNode;
try {
testNode = new LNode;
delete testNode;
return false;
}
catch(std::bad_alloc exception) {
return true;
}
}
int LLSList::GetLength() const {
LNode* LenPos = ListStart;
int length=0;
while (LenPos != NULL) {
LenPos=LenPos->next;
length++;
}
return length;
};
int LLSList::FindItem(int GetItem, LNode*& nodeIter) {
int position=0;
nodeIter=ListEnd;
while ((nodeIter != NULL) && (nodeIter->next !=ListEnd )
&& (nodeIter->next->item <gitem)) {
nodeIter=nodeIter->next;
position++; }
if ((nodeIter!=NULL)&&(nodeIter->next->item==gitem))
return position;
else
return -1;
}
/*int LLSList::GetItem(int gitem) {
int position=0;
LNode* nodeIter;
nodeIter=ListStart;
while ((nodeIter != NULL) && (nodeIter->item <gitem)) {
nodeIter=nodeIter->next;
position++; }
if ((nodeIter==NULL)||(nodeIter->item>gitem))
return -1;
else
return position;
}*/
int LLSList::GetItem(int gitem) {
LNode* unused_node;
return FindItem(gitem,unused_node);
}
void LLSList::MakeEmpty() {
LNode* tempPtr;
while (ListStart != NULL) {
tempPtr = ListStart;
ListStart = ListStart->next;
delete tempPtr;
}
}
/*void LLSList::PutItem(int newitem) {
LNode* newNode; //Get a pointer for a new node
LNode* leadptr; //This points to the "current" node when searching for correct location in which to place item
LNode* trailptr; //This points to the "previous" node when searching for correct location in which to place item
newNode = new LNode; //Allocate memory for the new node
newNode->item = newitem; // Store the item in the node
if ((ListStart == NULL) || (ListStart->item > newitem)) { //List is empty or first element less than element for retrieval)
newNode->next = ListStart; // Store address of next node
ListStart=newNode;
} else {
leadptr=ListStart->next;
trailptr=ListStart;
while ((leadptr!= NULL) && (leadptr->item<newitem)) {
leadptr=leadptr->next;
trailptr=trailptr->next;
}
newNode->next=leadptr;
trailptr->next=newNode;
}
}*/
void LLSList::PutItem(int newitem) {
LNode* newNode=new LNode;
newNode->item=newitem;
if (ListEnd==NULL) {
ListEnd=newNode;
ListEnd->next=ListEnd;
} else if (newNode->item>ListEnd->item){
newNode->next=ListEnd->next;
ListEnd->next=newNode;
ListEnd=newNode;
} else {
LNode* nodePred;
GetItem(newitem,nodePred);
newNode->next=NodePred->next;
nodePred->next=newNode;
}
}
/*void LLSList::DeleteItem(int ditem) {
LNode* nodeIter;
LNode* tmpNode;
LNode* leadptr; //This points to the "current" node when searching for correct location in which to place item
LNode* trailptr; //This points to the "previous" node when searching for correct location in which to place item
if (ListStart->item == ditem) {
tmpNode=ListStart;
ListStart=ListStart->next;
}
else{
leadptr=ListStart->next; //no empty lists allowed
trailptr=ListStart;
while (leadptr->item !=ditem) {
trailptr=leadptr;
leadptr=leadptr->next;
}
tmpNode=leadptr;
trailptr->next=leadptr->next;
}
delete(tmpNode);
}*/
bool LLSList::DeleteItem(int newitem) {
LNode* tmpNode;
int index;
LNode* nodePred;
index=FindItem(newitem,nodePred);
if (index==-1)
return false;
else {
tmpNode=nodePred->next;
if (ListEnd->next==ListEnd)
ListEnd=NULL;
else {
nodePred->next=tmpNode->next;
if (tmpNode==ListEnd)
ListEnd=nodePred;
}
delete(tmpNode);
return true;
}
}
void LLSList::ResetList() {
curPos=ListStart;
}
int LLSList::GetNextItem() {
if (curPos == NULL)
throw;
curPos=curPos->next;
return curPos->item;
};
/*void LLSList::PrintList() {
LNode* printPtr;
printPtr=ListStart;
std::cout<<"(";
while (printPtr != NULL) {
std::cout<<printPtr->item;
if (printPtr->next!=NULL)
std::cout<<", ";
printPtr=printPtr->next;
}
std::cout<<")"<<std::endl;
}*/
void LLSList::PrintList() {
LNode* printPtr=ListEnd->next;
std::cout<<"(";
while (printPtr != ListEnd) {
std::cout<<printPtr->item;
if (printPtr->next!=ListEnd)
std::cout<<", ";
printPtr=printPtr->next;
}
std::cout<<")"<<std::endl;
}