Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the delete function to delete a node 150 in the list c++ #include #include using namespace std; struct Student { int ID; double GPA;

Write the delete function to delete a node 150 in the list c++

#include

#include

using namespace std;

struct Student {

int ID;

double GPA;

int programs[5];

};

// user def data type

struct node {

int data;

node* nextNode;

};

void InsertAfter(node* node1, node* node2); //defining InsertAfter

void printList(node*); //defining printList

void InsertAfter(node* node1, node* node2) {

node1->nextNode = node2->nextNode;

node2->nextNode = node1;

}

void printList(node* head) {

cout

node* tmp = head;

while (tmp != nullptr) {

cout data

tmp = tmp->nextNode; // move the tmp ptr to the next node

}

}

void deleteNode() //----->

int main()

{

int* ptr1;

ptr1 = new int; //defining ptr1 as new int

(*ptr1) = 10; //setting the multiplier of ptr1

//Define the list

node* head; //creates a var called head

head = new node; // creates a node and store its address into var head

//same as line below

// node* head= new node;

//define head and node 1

head->data = 10; // (*head).data

head->nextNode = nullptr; //head reassigned nextNode

node* node1 = new node; //defining new node

node1->data = 100; //data in node1 set to 100

node1->nextNode = nullptr;

// call insert after

InsertAfter(node1, head);

// call print List

printList(head);

node* node2 = new node;

node2->data = 200;

node2->nextNode = nullptr;

InsertAfter(node2, node1);

printList(head);

node* node3 = new node;

node3->data = 150;

node3->nextNode = nullptr;

InsertAfter(node3, node1);

printList(head);

//deleteNode(150, head);

printList(head);

}

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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

e What blog software do you want to use?

Answered: 1 week ago

Question

e Either way, will your site use a Windows or Linux server?

Answered: 1 week ago

Question

e Do you care if your blog doesnt render perfectly in all browsers?

Answered: 1 week ago