Need help fixing the second line. I compile it, and it works fine, but the number is squished together below the first row #include "nodes_LLoLL.h" #include "cnPtrQueue.h" #include using namespace std; namespace CS3358_SP2023_A5P2 {         // do breadth-first (level) traversal and print data    void ShowAll_BF(PNode* pListHead, ostream& outs)    {         cnPtrQueue q;   CNode *cursor = 0;   while (pListHead != 0) {     if (pListHead->data != 0) {       q.push(pListHead->data);     }     pListHead = pListHead->link;   }   while (!q.empty()) {     cursor = q.front();     q.pop();     outs << cursor->data;     if (cursor->link != 0) {       q.push(cursor->link);     }   } }          void Destroy_cList(CNode*& cListHead)    {       int count = 0;       CNode* cNodePtr = cListHead;       while (cListHead != 0)       {          cListHead = cListHead->link;          delete cNodePtr;          cNodePtr = cListHead;          ++count;       }       cout << "Dynamic memory for " << count << " CNodes freed"            << endl;    }    void Destroy_pList(PNode*& pListHead)    {       int count = 0;       PNode* pNodePtr = pListHead;       while (pListHead != 0)       {          pListHead = pListHead->link;          Destroy_cList(pNodePtr->data);          delete pNodePtr;          pNodePtr = pListHead;          ++count;       }       cout << "Dynamic memory for " << count << " PNodes freed"            << endl;    }    // do depth-first traversal and print data    void ShowAll_DF(PNode* pListHead, ostream& outs)    {       while (pListHead != 0)       {          CNode* cListHead = pListHead->data;          while (cListHead != 0)          {             outs << cListHead->data << "  ";             cListHead = cListHead->link;          }          pListHead = pListHead->link;       }    } } #include "cnPtrQueue.h" #include using namespace std; namespace CS3358_SP2023_A5P2 { cnPtrQueue::cnPtrQueue()  {    numItems = 0;  } bool cnPtrQueue::empty() const { return outStack.empty() && inStack.empty(); } cnPtrQueue::size_type cnPtrQueue::size() const { return numItems; } CNode *cnPtrQueue::front() {   assert(!inStack.empty() || !outStack.empty());   if (outStack.empty()) {     while (!inStack.empty()) {       outStack.push(inStack.top());       inStack.pop();     }   }   return outStack.top(); } void cnPtrQueue::push(CNode *cnPtr) {   inStack.push(cnPtr);   numItems++; } void cnPtrQueue::pop() {   assert(!inStack.empty() || !outStack.empty());   if (outStack.empty()) {     while (!inStack.empty()) {       outStack.push(inStack.top());       inStack.pop();     }   }   outStack.pop();   numItems--; } } #include "nodes_LLoLL.h" #include using namespace std; using namespace CS3358_SP2023_A5P2; void Build_cList(int argc, CNode*& cListHead); void Build_pList(int argc, PNode*& pListHead); int main(int argc, char* argv[]) {    PNode* head_LLoLL = 0;    char reply;    do    {       Build_pList(argc, head_LLoLL);       ShowAll_DF(head_LLoLL, cout);       cout << endl;             ShowAll_BF(head_LLoLL, cout);       cout << endl;             Destroy_pList(head_LLoLL);       if (argc < 2)          cout << "Another? (n = no, others = yes) ";       cin >> reply;    }    while (reply != 'n' && reply != 'N');    return EXIT_SUCCESS; } void Build_cList(int argc, CNode*& cListHead) {    int oneInt;    char reply;    CNode* cListTail = cListHead;    if (argc < 2)       cout << "Add cList data? (n = no, others = yes) ";    cin >> reply;    while (reply != 'n' && reply != 'N')    {       if (argc < 2)          cout << "Enter cList data (int): ";       cin >> oneInt;       CNode* cNodePtr = new CNode;       cNodePtr->data = oneInt;       cNodePtr->link = 0;       if (cListTail == 0)          cListHead = cListTail = cNodePtr;       else       {          cListTail->link = cNodePtr;          cListTail = cNodePtr;       }       if (argc < 2)          cout << "Add more cList data? (n = no, others = yes) ";       cin >> reply;    } } void Build_pList(int argc, PNode*& pListHead) {    char reply;    PNode* pListTail = pListHead;    if (argc < 2)       cout << "Add cList to pList? (n = no, others = yes) ";    cin >> reply;    while (reply != 'n' && reply != 'N')    {       CNode* cListHead = 0;       Build_cList(argc, cListHead);       PNode* pNodePtr = new PNode;       pNodePtr->data = cListHead;       pNodePtr->link = 0;       if (pListTail == 0)          pListHead = pListTail = pNodePtr;       else       {          pListTail->link = pNodePtr;          pListTail = pNodePtr;       }       if (argc < 2)          cout << "Add more cList to pList? (n = no, others = yes) ";       cin >> reply;    } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question

Need help fixing the second line. I compile it, and it works fine, but the number is squished together below the first row

#include "nodes_LLoLL.h"
#include "cnPtrQueue.h"
#include <iostream>
using namespace std;

namespace CS3358_SP2023_A5P2
{
    
   // do breadth-first (level) traversal and print data
   void ShowAll_BF(PNode* pListHead, ostream& outs)
   {
        cnPtrQueue q;
  CNode *cursor = 0;
  while (pListHead != 0) {
    if (pListHead->data != 0) {
      q.push(pListHead->data);
    }
    pListHead = pListHead->link;
  }
  while (!q.empty()) {
    cursor = q.front();
    q.pop();
    outs << cursor->data;
    if (cursor->link != 0) {
      q.push(cursor->link);
    }
  }
}
     
   void Destroy_cList(CNode*& cListHead)
   {
      int count = 0;
      CNode* cNodePtr = cListHead;
      while (cListHead != 0)
      {
         cListHead = cListHead->link;
         delete cNodePtr;
         cNodePtr = cListHead;
         ++count;
      }
      cout << "Dynamic memory for " << count << " CNodes freed"
           << endl;
   }

   void Destroy_pList(PNode*& pListHead)
   {
      int count = 0;
      PNode* pNodePtr = pListHead;
      while (pListHead != 0)
      {
         pListHead = pListHead->link;
         Destroy_cList(pNodePtr->data);
         delete pNodePtr;
         pNodePtr = pListHead;
         ++count;
      }
      cout << "Dynamic memory for " << count << " PNodes freed"
           << endl;
   }

   // do depth-first traversal and print data
   void ShowAll_DF(PNode* pListHead, ostream& outs)
   {
      while (pListHead != 0)
      {
         CNode* cListHead = pListHead->data;
         while (cListHead != 0)
         {
            outs << cListHead->data << "  ";
            cListHead = cListHead->link;
         }
         pListHead = pListHead->link;
      }
   }
}

#include "cnPtrQueue.h"
#include <cassert>
using namespace std;
namespace CS3358_SP2023_A5P2 {
cnPtrQueue::cnPtrQueue() 

  numItems = 0; 
}

bool cnPtrQueue::empty() const { return outStack.empty() && inStack.empty(); }

cnPtrQueue::size_type cnPtrQueue::size() const { return numItems; }

CNode *cnPtrQueue::front() {
  assert(!inStack.empty() || !outStack.empty());
  if (outStack.empty()) {
    while (!inStack.empty()) {
      outStack.push(inStack.top());
      inStack.pop();
    }
  }
  return outStack.top();
}

void cnPtrQueue::push(CNode *cnPtr) {
  inStack.push(cnPtr);
  numItems++;
}

void cnPtrQueue::pop() {
  assert(!inStack.empty() || !outStack.empty());
  if (outStack.empty()) {
    while (!inStack.empty()) {
      outStack.push(inStack.top());
      inStack.pop();
    }
  }
  outStack.pop();
  numItems--;
}
}

#include "nodes_LLoLL.h"
#include <cstdlib>
using namespace std;
using namespace CS3358_SP2023_A5P2;
void Build_cList(int argc, CNode*& cListHead);
void Build_pList(int argc, PNode*& pListHead);
int main(int argc, char* argv[])
{
   PNode* head_LLoLL = 0;
   char reply;
   do
   {
      Build_pList(argc, head_LLoLL);
      ShowAll_DF(head_LLoLL, cout);
      cout << endl;
     
      ShowAll_BF(head_LLoLL, cout);
      cout << endl;
     
      Destroy_pList(head_LLoLL);
      if (argc < 2)
         cout << "Another? (n = no, others = yes) ";
      cin >> reply;
   }
   while (reply != 'n' && reply != 'N');
   return EXIT_SUCCESS;
}
void Build_cList(int argc, CNode*& cListHead)
{
   int oneInt;
   char reply;
   CNode* cListTail = cListHead;
   if (argc < 2)
      cout << "Add cList data? (n = no, others = yes) ";
   cin >> reply;
   while (reply != 'n' && reply != 'N')
   {
      if (argc < 2)
         cout << "Enter cList data (int): ";
      cin >> oneInt;
      CNode* cNodePtr = new CNode;
      cNodePtr->data = oneInt;
      cNodePtr->link = 0;
      if (cListTail == 0)
         cListHead = cListTail = cNodePtr;
      else
      {
         cListTail->link = cNodePtr;
         cListTail = cNodePtr;
      }
      if (argc < 2)
         cout << "Add more cList data? (n = no, others = yes) ";
      cin >> reply;
   }
}

void Build_pList(int argc, PNode*& pListHead)
{
   char reply;
   PNode* pListTail = pListHead;
   if (argc < 2)
      cout << "Add cList to pList? (n = no, others = yes) ";
   cin >> reply;
   while (reply != 'n' && reply != 'N')
   {
      CNode* cListHead = 0;
      Build_cList(argc, cListHead);
      PNode* pNodePtr = new PNode;
      pNodePtr->data = cListHead;
      pNodePtr->link = 0;
      if (pListTail == 0)
         pListHead = pListTail = pNodePtr;
      else
      {
         pListTail->link = pNodePtr;
         pListTail = pNodePtr;
      }
      if (argc < 2)
         cout << "Add more cList to pList? (n = no, others = yes) ";
      cin >> reply;
   }
}

others = yes) y
Add more clist data? (n = no, others = yes) y
Enter cList data (int): 12
Add more cList data? (n = no,
Enter cList data (int): 13
Add more cList data? (n = no,
Enter cList data (int): 14
Add more cList data? (n = no,
others = yes) y
others = yes) n
Add more cList to pList? (n = no, others = yes) n
11 12 13 14
11121314
Dynamic memory for 4 CNodes freed
Dynamic memory for 1 PNodes freed
Another? (n = no, others = yes) y
Add cList to pList? (n = no, others = yes) y
others = yes) n
no, others = yes) y
Add cList data? (n = no,
Add more cList to pList?
Add cList data? (n no,
Enter cList data (int): 21
Add more cList data? (n
Enter cList data (int): 22
Add more cList data? (n
Enter cList data (int): 23
Add more cList data? (n =
Enter cList data (int): 24
Add more cList data? (n =
no,
others = yes) y
no,
others = yes) y
no, others = yes) n
Add more cList to pList? (n = no, others = yes) n
21 22 23 24
(n = no, others = yes) y
others = yes) y
21222324
Dynamic memory for CNodes freed
Dynamic memory for 4 CNodes freed
Dynamic memory for 2 PNodes freed
Another? (n = no, others = yes) y
Add cList to pList? (n = no, others = yes) y
Add cList data? (n = no, others = yes) y
Enter cList data (int): 11
others = yes) y
Add more cList data? (n = no, others = yes) y
Enter cList data (int): 12
Add more cList data? (n = no,
Enter cList data (int): 13
Add more cList data? (n = no,
Enter cList data (int): 14
Add more cList data? (n = no,
Add more cList to pList? (n = no, others = yes) y
Add cList data? (n = no, others = yes) n
others = yes) y
others = yes) n
Add more clist to pList? (n = no, others = yes) n
11 12 13 14
11121314
Dynamic memory for 4 CNodes freed
Dynamic memory for CNodes freed
Dynamic memory for 2 PNodes freed
Another? (n = no, others = yes) y
Add list to plin+2 (a
othong
Transcribed Image Text:others = yes) y Add more clist data? (n = no, others = yes) y Enter cList data (int): 12 Add more cList data? (n = no, Enter cList data (int): 13 Add more cList data? (n = no, Enter cList data (int): 14 Add more cList data? (n = no, others = yes) y others = yes) n Add more cList to pList? (n = no, others = yes) n 11 12 13 14 11121314 Dynamic memory for 4 CNodes freed Dynamic memory for 1 PNodes freed Another? (n = no, others = yes) y Add cList to pList? (n = no, others = yes) y others = yes) n no, others = yes) y Add cList data? (n = no, Add more cList to pList? Add cList data? (n no, Enter cList data (int): 21 Add more cList data? (n Enter cList data (int): 22 Add more cList data? (n Enter cList data (int): 23 Add more cList data? (n = Enter cList data (int): 24 Add more cList data? (n = no, others = yes) y no, others = yes) y no, others = yes) n Add more cList to pList? (n = no, others = yes) n 21 22 23 24 (n = no, others = yes) y others = yes) y 21222324 Dynamic memory for CNodes freed Dynamic memory for 4 CNodes freed Dynamic memory for 2 PNodes freed Another? (n = no, others = yes) y Add cList to pList? (n = no, others = yes) y Add cList data? (n = no, others = yes) y Enter cList data (int): 11 others = yes) y Add more cList data? (n = no, others = yes) y Enter cList data (int): 12 Add more cList data? (n = no, Enter cList data (int): 13 Add more cList data? (n = no, Enter cList data (int): 14 Add more cList data? (n = no, Add more cList to pList? (n = no, others = yes) y Add cList data? (n = no, others = yes) n others = yes) y others = yes) n Add more clist to pList? (n = no, others = yes) n 11 12 13 14 11121314 Dynamic memory for 4 CNodes freed Dynamic memory for CNodes freed Dynamic memory for 2 PNodes freed Another? (n = no, others = yes) y Add list to plin+2 (a othong
1 #ifndef NODES_LLOLL_H
2 #define NODES_LLOLL_H
4N3 4 5 7
6
8
9
аидшино 00 au Pшиноо 00
7 ~ {
0
1
_2
_3
4
5
6
_7 ~
_8
9
1
2
3
4
6
27
8
TO 00
-9
30
V
=1
#include <iostream>
namespace CS3358_SP2023_A5P2
// child node
struct CNode
{
}
int data;
CNode* link;
};
// parent node
struct PNode
{
};
CNode* data;
PNode* link;
// for ostream
// toolkit functions for LLOLL based on above node definitions
void Destroy_cList (CNode*& cListHead);
void Destroy_pList (PNode* & pListHead);
void ShowAll_DF (PNode* pListHead, std::ostream& outs);
void ShowAll_BF (PNode* pListHead, std::ostream& outs);
#endif
Transcribed Image Text:1 #ifndef NODES_LLOLL_H 2 #define NODES_LLOLL_H 4N3 4 5 7 6 8 9 аидшино 00 au Pшиноо 00 7 ~ { 0 1 _2 _3 4 5 6 _7 ~ _8 9 1 2 3 4 6 27 8 TO 00 -9 30 V =1 #include <iostream> namespace CS3358_SP2023_A5P2 // child node struct CNode { } int data; CNode* link; }; // parent node struct PNode { }; CNode* data; PNode* link; // for ostream // toolkit functions for LLOLL based on above node definitions void Destroy_cList (CNode*& cListHead); void Destroy_pList (PNode* & pListHead); void ShowAll_DF (PNode* pListHead, std::ostream& outs); void ShowAll_BF (PNode* pListHead, std::ostream& outs); #endif
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Types of Linked List
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education