Question: Need help debugging thiis program. Output is an infinite loop of: Also need help writing the copy constructor. Full code is as follows: main.cpp #include
Need help debugging thiis program. Output is an infinite loop of:

Also need help writing the copy constructor.
Full code is as follows:
main.cpp
#include
#include
#include "llist.hpp"
using namespace std;
int main(){
int n;
LList somenums;
for(int i = 0; i
{ n = rand()%700 + 1;
somenums.add_item(n);
}
// Once you have written the rear-view this should let you
// see the list frontwards and backwards.
somenums.frontview();
somenums.rearview();
// This part will be uncommented once you have written the copy constructor
/*
{
LList numcopy(somenums); // call to the copy constructor
numcopy.frontview();
numcopy.rearview();
} // Line 34 - What happens here?
// Checking the original list
somenums.frontview();
somenums.rearview();
*/
return 0;
}
llist.cpp
#include
#include "llist.hpp"
using namespace std;
void LList::frontview()const{
node* cursor = head;
while (cursor != NULL){
coutdata()
cursor = cursor->next();
}
}
// The student is required to write the implementation of this function
void LList::rearview()const{
node* cursor = tail;
while (cursor != NULL){
coutdata()
cursor = cursor->previous();
}
}
void LList::add_item(int item){
if(head == NULL){
head=tail=new node(item);
nodecount++;
}
else if(item%5 == 0 && nodecount > 3){
int i = 0;
node* cursor=head;
while(i
cursor = cursor->next();
i++;
}
cursor->previous()->set_next(new node(item,cursor->next(),cursor->previous()));
nodecount++;
}
else{
tail->set_next(new node(item, tail));
tail = tail->next();
nodecount++;
}
}
LList::~LList(){
node* rmptr;
while(head != NULL){
rmptr=head;
head = head->next();
delete rmptr;
}
}
llist.h
#include
class node{
public:
node(int d = 0, node* p = NULL, node* n = NULL){
datafield = d; previousptr=p; nextptr = n;
}
int data() {return datafield;}
node *previous() {return previousptr;}
node *next() {return nextptr;}
void set_data(int d){datafield = d;}
void set_previous(node * p){previousptr = p;}
void set_next(node *n) {nextptr = n;}
private:
int datafield;
node *nextptr;
node *previousptr;
};
class LList{
public:
LList(){
head = tail = NULL;
nodecount = 0;
}
void add_item(int item);
void frontview()const;
void rearview() const;
~LList();
int size()const {return nodecount;}
//LList(const LList& other);
private:
node* head;
node* tail;
int nodecount;
};
8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310 8 310
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
