Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

8:52 AM blackboard.wichita.edu .11 AT&T; Member function delete node (data) inpu

ID: 3586878 • Letter: 8

Question

8:52 AM blackboard.wichita.edu .11 AT&T; Member function delete node (data) input: data to be deleted from list output: None returns: True if deleted, false if not in list prev- NULL cur head while (curTNULL and curr data- data) prevcurT curr curr link end while if currNULL if prev- NULL W Deleting first node head curr link W Deleting other nodes Prev link = curr link free Node len-len-1 return True end if return False Member function retrieve node (data) input: data to be found in list output: data returns: data curr -head while (curTNULL&& curr data data) curr curr link return curr data return 0 if curr != NULL Member function is empty input: None output return: True if empty, false if not if list count- or if head NULL return True return False Member function list count input: Nonde output/Return: number of items in list return list len

Explanation / Answer

Please check below programme , Comment if you face any problems #include using namespace std; struct Node { int data; Node* next; }; //Head node of Linked list struct Node *head = NULL; //Method to inset new Node void insertNode(int data) { Node *newNode = new Node; newNode->data = data; newNode->next = NULL; if(head == NULL){ head = newNode; return; } Node *cur = head; //Loop all nodes till the end and insert element at end while(cur) { if(cur->next == NULL) { cur->next = newNode; return; } cur = cur->next; } } //Function to delete Node bool delete_node(int data){ Node *prev = NULL; //Start from head Node *current = head; //Loop until node found while(current != NULL && current->data != data){ prev = current; current = current->next; } if(prev != NULL && current != NULL){ //Delete Node prev->next = current->next; delete current; current = NULL; return true; } else{ return false; } } //Function to retreive Node int retrieve_node(int data,int output){ //Start from head Node *current = head; //Loop until node found while(current != NULL && current->data != data){ current = current->next; } if(current != NULL){ output = current->data; return current->data; } else{ return 0; } } //Function to check is Empty bool isEmpty(){ //If Head is NULL then its empty if(head){ return false; } else{ return true; } } //Function to get List count int list_count(){ int count = 0; //Start from head Node *current = head; //Loop until node found while(current != NULL ){ //increment count count++; current = current->next; } return count; } int main(int argc, char *argv[]) { //Test //insert Some nodes insertNode(1); insertNode(78); insertNode(198); insertNode(786); insertNode(1); insertNode(45); insertNode(3333); insertNode(7836); //Test is Empty cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote