Question: Need help with my code, keep getting this error - Exited with return code - 6 ( SIGABRT ) . free ( ) : double
Need help with my code, keep getting this error Exited with return code SIGABRT free: double free detected in tcache
#include
#include
using namespace std;
class MileageTrackerNode
public:
double miles;
string date;
MileageTrackerNode nextNodePtr;
Constructor
MileageTrackerNodedouble miles, string date : milesmiles datedate nextNodePtrnullptr
InsertAfter function
void InsertAfterMileageTrackerNode nodePtr
nodePtrnextNodePtr thisnextNodePtr;
thisnextNodePtr nodePtr;
PrintNodeData function
void PrintNodeData
cout miles date endl;
;
int main
int numNodes;
cin numNodes;
Dummy head node not to be printed
MileageTrackerNode headNode new MileageTrackerNode;
MileageTrackerNode lastNode headNode;
Reading nodes and building the linked list
for int i ; i numNodes; i
double miles;
string date;
cin miles date;
MileageTrackerNode newNode new MileageTrackerNodemiles date;
lastNodeInsertAfternewNode;
lastNode newNode; Move to the new last node
Printing nodes skipping the dummy head node
MileageTrackerNode currentNode headNodenextNodePtr;
while currentNode nullptr
currentNodePrintNodeData;
currentNode currentNodenextNodePtr;
Cleanup free allocated memory
currentNode headNode;
while currentNode nullptr
MileageTrackerNode tempNode currentNode;
currentNode currentNodenextNodePtr;
delete tempNode;
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
