struct node { int key; struct node *next; }; typedef struct node NODE; typedef s
ID: 3615777 • Letter: S
Question
struct node {
int key; struct node *next;
};
typedef struct node NODE;
typedef struct node *PTR;
Write a C function delete_last_occurwith thefollowing header:
void delete_last_occur (PTR *h, int j)
The parameter *h points to a listcontaining nodes of type NODE. When the list isnonempty, several
nodes in the list may have the same value forthe key field. The function should do the following.If
the list contains one or more nodes whose key values areequal to that of the parameter j, thefunction
should delete last node with key valueequal to that of j. If the list does not containany node with
keyvalue equal to that of j, the function should returnwithout modifying the list.
Explanation / Answer
//I hope this will be helpful for you And Remember // Don't Forget about my credit // If you need any other related to datastructure then send meprivate message May be i will be helpful for you. #include<constream.h> struct Node{ int key; struct Node* next; }; class Linklist{ // if you don't have concept of class then you just selectdefinition of remove function and use it. private: struct Node*first; // this is same as*h public: Linklist(); //constructor void remove(Node*,int); // remove function prototype }; Linklist::Linklist(){ first=NULL; } void Linklist::remove(int key){ struct Node* temp=first; //first node address is assigned to struct Node type pointer struct Node* prev=temp; // thispointer will store address of previous node of temp in whileloop given below // it is supposed that first points to leftfirst node while(temp!=NULL){ prev=temp; if(temp->key==key){ prev->next=temp->next; deletetemp; break; } temp=temp->next; } }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.