Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is data structure class. I need a code in C++. Please, give screen shot of running program. Below is my program, it is a

This is data structure class. I need a code in C++. Please, give screen shot of running program. Below is my program, it is a linked list with 2 nodes. 
You can use this or write a similar one. 
I am trying to write 2 functions. One function will add another node at the end of the list. The other function will delete a node. Please, do not use dangling pointers ! 
Thank you. 

image text in transcribed

#include using namespace std; class Node { int data; Node *next; public: void setdata(int d) {data = d;} void setnext(Node *p) { next = p; } int getdata() {return data;} Node getnext() {return *next;} }; int main() { Node *N1 = new Node; N1->setdata(1000); Node *N2 = new Node; N2->setdata(2000); N1->setnext( N2) ; N2->setnext(NULL); system("pause"); return 0; } 

Please, do not copy from other chegg answers for this questions.

#include using namespace std; class Node int data; Node *next; public: void setdata(int d) void setnext (Node *p) next - p; > int getdata) freturn data;h {data = d;} Node getnext() (return *next; int main() Node *N1 = new Node ; N1->setdata(1000); Node *N2 new Node; N2->setdata(2000); N1->setnext( N2); N2->setnext (NULL); system("pause"); return 0

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

Students also viewed these Databases questions