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; } }
Types of Linked List
A sequence of data elements connected through links is called a linked list (LL). The elements of a linked list are nodes containing data and a reference to the next node in the list. In a linked list, the elements are stored in a non-contiguous manner and the linear order in maintained by means of a pointer associated with each node in the list which is used to point to the subsequent node in the list.
Linked List
When a set of items is organized sequentially, it is termed as list. Linked list is a list whose order is given by links from one item to the next. It contains a link to the structure containing the next item so we can say that it is a completely different way to represent a list. In linked list, each structure of the list is known as node and it consists of two fields (one for containing the item and other one is for containing the next item address).
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fa3dbb91f-777d-47b2-aa94-40b3e17142a5%2F3ba0d59c-56d1-48bd-af3f-b34c9126447a%2F3zbpz3_processed.png&w=3840&q=75)
![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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fa3dbb91f-777d-47b2-aa94-40b3e17142a5%2F3ba0d59c-56d1-48bd-af3f-b34c9126447a%2Fhk7mxqi_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)