Question: Write the delete function to delete a node 150 in the list c++ #include #include using namespace std; struct Student { int ID; double GPA;
#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
Get step-by-step solutions from verified subject matter experts
