Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can someone help he fix these codes please! I just need to create a copy of this linked list RECURSIVELY. I keep getting a segmentation

can someone help he fix these codes please! I just need to create a copy of this linked list RECURSIVELY.

I keep getting a segmentation fault.

// This is the header file (list.h)

#include #include #include using namespace std; struct node { int data; //some questions are a char * data; node * next; };

class list { public: //These functions are already written for you list(); //supplied ~list(); //supplied void build(); //supplied void display(); //supplied /* *****************YOUR TURN! ******************************** */ //Write your function prototype here: void duplicate(node *& newHead); void duplicate(node * original, node *& newHead);

private: //notice there is both a head and a tail! node * head; node * tail; }; *************************************************************************************************************************************************

// This is the cpp file (function.cpp)

#include "list.h" void list::duplicate(node *& newHead) { node * original; if(head == NULL) return ; else duplicate(original, newHead); }

void list::duplicate(node * original, node *& newHead) { newHead = new node; newHead->data = original->data; newHead->next = original->next; duplicate(original->next, newHead->next); }

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

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions