the problem with my code, well as far as i know its the functions "Print", "Print Reverse" and "PrintFrom".
the "Print" function prints the list in appending order, "Print Reverse" in reverse order, and "PrintFrom" is from a specific number, in this code , (62).
there are other problems too, if u can please help , i hate the crap right now
=====================
Tagged by SalemCode:struct NodeType; struct NodeType { int component; NodeType* link; NodeType* backlink; }; class ClosedList { public: bool IsEmpty() const; void Append(int item); int TotalCount(); void Print() const; void PrintReverse() const; //void PrintFrom(int item) const; void Delete(int item); ClosedList(); //~ClosedList(); ClosedList(const ClosedList& otherList); private: NodeType* head; }; ===================== #include "closedlist.h" #include <iostream> using namespace std; void main() { ClosedList Scores; Scores.Append(92); Scores.Append(82); Scores.Append(62); Scores.Append(72); Scores.Append(99); cout <<"\nThe total count of the list is "<< Scores.TotalCount() <<endl; cout <<"\nThe list in the order of appending\n "; Scores.Print(); cout <<"\nThe list in the reverse order of appending\n "; Scores.PrintReverse(); cout <<"\nThe list in the order of appending starting from 62\n "; Scores.PrintFrom(62); cout <<"\nThe list after deleting 92:\n "; Scores.Delete(92); Scores.Print(); cout <<"\nThe list after deleting 72:\n "; Scores.Delete(72); Scores.Print(); ClosedList AnotherScores(Scores); cout <<"\nThe copied list: \n"; AnotherScores.Print(); } ========================== #include "ClosedList.h" #include <iostream> #include <cstddef> using namespace std; ClosedList::ClosedList() { head = NULL; } ClosedList::ClosedList( const ClosedList& otherList ) { NodeType* fromPtr; NodeType* toPtr; if (otherList.head == NULL) { head = NULL; return; } fromPtr = otherList.head; head = new NodeType; head->component = fromPtr->component; toPtr = head; fromPtr = fromPtr->link; while (fromPtr != NULL) { toPtr->link = new NodeType; toPtr = toPtr->link; toPtr->component = fromPtr->component; fromPtr = fromPtr->link; } toPtr->link = NULL; } /*ClosedList::~ClosedList() { int temp; while (!IsEmpty()) PrintFrom(temp); }*/ bool ClosedList::IsEmpty() const { return (head == NULL); } void ClosedList::Print() const { NodeType* currPtr = head; if(!IsEmpty()) { do { cout << currPtr->component << " "; currPtr = currPtr->link; }while (currPtr->link != head); } cout <<endl; } void ClosedList::PrintReverse() const { NodeType* currPtr = head->backlink; if(!IsEmpty()) { do { cout << currPtr->component << " "; currPtr = currPtr->backlink; }while (currPtr->backlink != head); } cout <<endl; } void ClosedList::Append(int item) { NodeType* newNodePtr = new NodeType; newNodePtr->component = item; if(IsEmpty()) { head = newNodePtr; newNodePtr->link = head; newNodePtr->backlink = head; } else { newNodePtr->link = head; newNodePtr->backlink = head->backlink; head->backlink->link = newNodePtr; head->backlink = newNodePtr; head = newNodePtr; } //cout << head->component << "is appended\n"; } void ClosedList::PrintFrom(int item) const { NodeType* tempPtr = head; item = head->component; head = head->link; delete tempPtr; } void ClosedList::Delete(int item) { NodeType* delPtr; NodeType* currPtr; if (item == head->component) { delPtr = head; head = head->link; } else { currPtr = head; while (currPtr->link->component != item) { currPtr = currPtr->link; } delPtr = currPtr->link; currPtr->link = currPtr->link->link; } delete delPtr; } ClosedList::TotalCount() { NodeType* currPtr = head; int TotalCount = 0; do { TotalCount++; currPtr = currPtr->link; }while (currPtr != head); return TotalCount; }



LinkBack URL
About LinkBacks


