Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Unsure of where the double free is or how to correct. Need to resolve this error: Exited with return code - 6 ( SIGABRT )
Unsure of where the double free is or how to correct. Need to resolve this error:
Exited with return code SIGABRT
free : double free detected in tcache
header file
#include
#include
#include
using namespace std;
template
struct Node
Node next;
T data;
;
template class LinkedList
public:
Node first;
Node last;
LinkedList
first NULL;
last NULL;
void AddHeadT data
if first NULL
Node temp new Node;
tempdata data;
tempnext NULL;
first temp;
last temp;
else
Node temp new Node;
tempdata data;
tempnext first;
first temp;
void AddTailT data
if last NULL
Node temp new Node;
tempdata data;
tempnext NULL;
first temp;
last temp;
else
Node temp new Node;
tempdata data;
tempnext NULL;
lastnext temp;
last temp;
void AddNodesHeadT data int size
for int i ; i size; i
thisAddHeaddatai;
void AddNodesTailT data int size
for int i ; i size; i
thisAddTaildatai;
int NodeCount
if first NULL
return ;
Node temp first;
int count ;
while temp last
count ;
temp tempnext;
return count;
void PrintForward
if first NULL
cout "List IS empty!!!" endl;
Node temp first;
do
cout tempdata endl;
temp tempnext;
while temp last;
cout endl;
void PrintReverse
if first NULL
cout "List is empty!!!" endl;
return;
std::vector listdatathisNodeCount;
Node temp first;
int i ;
while temp NULL
listdatai tempdata;
temp tempnext;
Print the vector in reverse order
for int i listdata.size; i ; i
cout listdatai endl;
~LinkedList
Node temp nullptr;
while temp last
temp first;
first firstnext;
freetemp;
freefirst;
freelast;
;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started