Answered step by step
Verified Expert Solution
Link Copied!

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 -6(SIGABRT).
free() : double free detected in tcache 2
//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 AddHead(T data){
if (first == NULL){
Node* temp = new Node();
temp->data = data;
temp->next = NULL;
first = temp;
last = temp;
}
else {
Node* temp = new Node;
temp->data = data;
temp->next = first;
first = temp;
}
}
void AddTail(T data){
if (last == NULL){
Node* temp = new Node();
temp->data = data;
temp->next = NULL;
first = temp;
last = temp;
}
else {
Node* temp = new Node();
temp->data = data;
temp->next = NULL;
last->next = temp;
last = temp;
}
}
void AddNodesHead(T data[], int size){
for (int i =0; i < size; i +=1){
this->AddHead(data[i]);
}
}
void AddNodesTail(T data[], int size){
for (int i =0; i < size; i +=1){
this->AddTail(data[i]);
}
}
int NodeCount(){
if (first == NULL){
return 0;
}
Node* temp = first;
int count =1;
while (temp != last){
count +=1;
temp = temp->next;
}
return count;
}
void PrintForward(){
if (first == NULL){
cout << "List IS empty!!!" << endl;
}
Node* temp = first;
do {
cout << temp->data << endl;
temp = temp->next;
} while (temp != last);
cout <<"0"<< endl;
}
void PrintReverse(){
if (first == NULL){
cout << "List is empty!!!" << endl;
return;
}
std::vector listdata(this->NodeCount());
Node* temp = first;
int i =0;
while (temp != NULL){
listdata[i++]= temp->data;
temp = temp->next;
}
// Print the vector in reverse order
for (int i = listdata.size()-1; i >=0; i--){
cout << listdata[i]<< endl;
}
}
~LinkedList(){
Node* temp = nullptr;
while (temp != last){
temp = first;
first = first->next;
free(temp);
}
free(first);
free(last);
}
};

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 15th International Conference Dasfaa 2010 International Workshops Gdm Benchmarx Mcis Snsmw Diew Udm Tsukuba Japan April 2010 Revised Selected Papers Lncs 6193

Authors: Masatoshi Yoshikawa ,Xiaofeng Meng ,Takayuki Yumoto ,Qiang Ma ,Lifeng Sun ,Chiemi Watanabe

2010th Edition

3642145884, 978-3642145889

Students also viewed these Databases questions

Question

5. Identify three characteristics of the dialectical approach.

Answered: 1 week ago

Question

7. Identify six intercultural communication dialectics.

Answered: 1 week ago