vendredi 26 avril 2019

Program is freezing up when I attempt to run it and I am not able to locate the source of the error

My program is supposed to take a text file with certain characters and give a corresponding output depending on which characters are listed. I have completed the code for all functions, but when I try to test the program it freezes up on one of the outputs which is supposed to output the list as a string.

I assume it is an issue with either my toString function or my implementation of it, but I have looked through the code multiple times and I still cannot find a solution to stop the program from freezing up at the same point.

Implementation of toString function:

 case 'P':
         if (DList == nullptr)
         {
           cout << "MUST CREATE LIST INSTANCE"
                << endl;
         }
         else
         {
           if (DList->empty())
           {
             cout << "LIST EMPTY"
                  << endl;
           }
           else
           {
             cout << DList->toString() << endl;
           }
         }
         // cout << "test P" << endl;
         break;

toString function:

string toString() const
{
  ostringstream temp;

  Node* marker = head;
  while (marker != nullptr)
  {
    temp << marker->value;
    if (marker->next != nullptr)
    {
      temp << ",";
      marker = marker->next;
    }
  }//end of while loop
  temp << '\n';
  return temp.str();
}

Text input file I am using to run:

# create first list
C
P <-- List is empty here so the program outputs correctly.
F 25
B 5
F 20
B 5
F 10
F 25
A
N
P <-- Point where program freezes up and outputs nothing.
Z
R 5
E 25
G 1
G 5
G 25
N
P
T
K
N
P
X
K
P
D
X

This is what I should be seeing in my output:

LIST CREATED
LIST EMPTY
VALUE 25 ADDED TO HEAD
VALUE 5 ADDED TO TAIL
VALUE 20 ADDED TO HEAD
VALUE 5 ADDED TO TAIL
VALUE 10 ADDED TO HEAD
VALUE 25 ADDED TO HEAD
VALUE 25 AT HEAD
LIST SIZE IS 6
25,10,20,25,5,5 <-- This is where the program freezes up and doesn't output anything
VALUE 5 AT TAIL
VALUE 5 REMOVED
VALUE 25 ELIMINATED
VALUE 1 NOT FOUND
VALUE 5 FOUND
VALUE 25 NOT FOUND
LIST SIZE IS 3
10,20,5
REMOVED HEAD
REMOVED TAIL
LIST SIZE IS 1
20
LIST CLEARED
LIST EMPTY
LIST EMPTY
LIST DELETED
MUST CREATE LIST INSTANCE

This is what I am getting:

LIST CREATED
LIST EMPTY
VALUE 25 ADDED TO HEAD
VALUE 5 ADDED TO TAIL
VALUE 20 ADDED TO HEAD
VALUE 5 ADDED TO TAIL
VALUE 10 ADDED TO HEAD
VALUE 25 ADDED TO HEAD
VALUE 25 AT HEAD
LIST SIZE IS 6
                  (Blank line where program freezes/locks up)

Aucun commentaire:

Enregistrer un commentaire