Question
implement delete node function in c++ language

// Delete node containing word from list if it is present void delNode (DLList list, char *str) (

I just need a basic doubly linked list code for the delete node portion of the code
1 0
Add a comment Improve this question Transcribed image text
Answer #1

#give it a thumbs up

c++ code

#include <bits/stdc++.h> #include-string . h> using namespace std; 4 7 II/doubly linked list structNode 8 9 10 char arr[25];27 28 29 if ( ( str㎝p ( temp->arr, str)=-0) &&temp=start) //change head pointer *thead = *temp->next; start *head; start->pre51 52 53 54 55 L temp temp->next; return;

OUTPUT

Original Linked list goodbye bye hello hi node to be deleted: hi Modified Linked list goodbye bye hello

Original Linked list goodbye bye hello hi node to be deleted: hello Modified Linked list goodbye bye hi

Original Linked list goodbye bye hello hi node to be deleted: goodbye Modified Linked list bye hello hi

Code text

// C++ program to delete a node from
// Doubly Linked List
#include <bits/stdc++.h>
#include<string.h>
using namespace std;

//doubly linked list
struct Node
{
   char arr[25];
   Node* next;
   Node* prev;
};

// Function to delete a node in a Doubly Linked List.
void deleteNode(Node** head, char *str)
{
   // base case
   if (*head == NULL)
       return;

Node* temp = *head;
Node* start = *head;
while(temp!=NULL)
{
//starting node
if((strcmp(temp->arr,str)==0)&&temp==start)
{
//change head pointer to second node
**head = *temp->next;
start = *head;
start->prev=NULL;

}
//last node
else if((strcmp(temp->arr,str)==0)&&temp->next==NULL)
{
//put NULL to second last node
temp=temp->prev;
temp->next=NULL;
}
//other nodes
else if((strcmp(temp->arr,str)==0))
{
//put next address to previous node and previous address to next node
Node* temp2;
temp2=temp->prev;
temp=temp->next;
temp2->next=temp;
temp->prev=temp2;
}
temp = temp->next;
}
return;
}

#comment for any queries

Add a comment
Know the answer?
Add Answer to:
implement delete node function in c++ language I just need a basic doubly linked list code for the delete node portion of the code // Delete node containing word from list if it is present void...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • implement a doubly-linked list in C. Each node in the linked list should contain a string,...

    implement a doubly-linked list in C. Each node in the linked list should contain a string, a pointer to the previous node (or NULL), and a pointer to the next node (or NULL). The nodes should be sorted by their strings. struct node_t { char* str; struct node_t* prev; struct node_t* next; } To maintain the doubly-linked list, you should keep a pointer to the head node of the list (or NULL if the list is empty), and a pointer...

  • C++ NEED HELP WITH MY REVERSE STRING FUNCTION IN LINK LIST A function Reverse, that traverses...

    C++ NEED HELP WITH MY REVERSE STRING FUNCTION IN LINK LIST A function Reverse, that traverses the linked list and prints the reverse text to the standard output, without changing the linked list. ( Pass the linked list by value, you have the freedom to create a doubly linked list that is a copy of the original list in your program before you call the function) #include "pch.h" #include <iostream> #include <string.h> #include <string> using namespace std; #define MAX 512...

  • Programming in C: I am trying to modify this linked list to be doubly linked list....

    Programming in C: I am trying to modify this linked list to be doubly linked list. I’m also trying to add a print in reverse function. I’m really struggling with how to change the insert function to doubly link the nodes without effecting the alphabetical sorting mechanism. Example of desired output: Enter your choice: 1 to insert an element into the list. 2 to delete an element from the list. 3 to end. ? 1 Enter a character: a The...

  • In C++ - Learn how to implement linked lists Part 1 Node and Linked List Class...

    In C++ - Learn how to implement linked lists Part 1 Node and Linked List Class (50 pts): Create node with public properties: Block type block and block ptr next. Create a linked list class that uses the node you generated without an add or delete method with a head and optional tail and counter. Make a driver that generates a node to test your implementation. Part 2 Add Method (30 pts): Create an add method in your linked list...

  • 1.Implement recursive and iterative delete functions for linked lists. Node declaration of the linked list is...

    1.Implement recursive and iterative delete functions for linked lists. Node declaration of the linked list is given below. struct node { int info; struct node *next; }; typedef struct node node; You can assume that all the nodes in the linked list are distinct and each node appears in the list at most once. Prototype of the functions are given below. node *delete(node *head, int k) node *recursivedelete(node *head, int k) • delete deletes the node with info k from...

  • Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a...

    Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a function that finds if a given value is present in a linked-list. The function should look for the first occurrence of the value and return a true if the value is present or false if it is not present in the list. Your code should work on a linked-list of any size including an empty list. Your solution must be RECURSIVE. Non-recursive solutions will...

  • BELOW IS THE CODE I ALREADY HAVE Linked List - Delete Modify Lab 5 and include...

    BELOW IS THE CODE I ALREADY HAVE Linked List - Delete Modify Lab 5 and include the method to delete a node from the Linked List. In summary: 1) Add the method Delete 2) Method call to delete, with a number that IS in the list 3) Method call to delete, with a number that is NOT in the list - Be sure to include comments - Use meaningful identifier names (constants where appropriate) import java.io.*; 1/ Java program to...

  • I need help with encoding a doubly-linked list, which must include a function that sorts the...

    I need help with encoding a doubly-linked list, which must include a function that sorts the name field in the bubble method, it must be encoded in the c language.

  • Using C++ language, Design and implement a class representing a doubly linked list. The class must...

    Using C++ language, Design and implement a class representing a doubly linked list. The class must have the following requirements: The linked list and the nodes must be implemented as a C++ templates The list must be generic – it should not implement arithmetic/logic functions. (template class) It must include a destructor and a copy constructor It must include methods to insert at the front and at the back of the list It must include a method to return the...

  • I need this in C++. This is all one question Program 2: Linked List Class For...

    I need this in C++. This is all one question Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we'll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT