Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help creating an insertAfter function which inserts a node after the value passed by reference. I have attached what I have written but

I need help creating an insertAfter function which inserts a node after the value passed by reference. I have attached what I have written but it does not work.

#include

#include

class DoublyLinkedList {

public:

DoublyLinkedList();

~DoublyLinkedList();

void append (const string& s);

void insertBefore (const string& s);

void insertAfter (const string& s);

void remove (const string& s);

bool empty();

void begin();

void end();

bool next();

bool prev();

bool find(const string& s);

const std::string& getData() const;

private:

class Node

{

public:

Node();

Node(const string& data);

~Node();

Node* next;

Node* prev;

string* data;

};

Node* head;

Node* tail;

Node* current;

};

#endif

void DoublyLinkedList::insertAfter(const string& s)

{

Node *temp, *var;

var=(Node *)malloc(sizeof(Node));

if(head == NULL)

{

append(s);

}

temp->data=current;

}

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

Intelligent Image Databases Towards Advanced Image Retrieval

Authors: Yihong Gong

1st Edition

1461375037, 978-1461375036

More Books

Students also viewed these Databases questions