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...

  • C LANGUAGE I just need the void push() function, which inserts new node to the front...

    C LANGUAGE I just need the void push() function, which inserts new node to the front of the list #include<stdio.h> #include<stdlib.h> typedef struct node { int data; struct node *next; } Node; //Creating head a as a global Node* Node *head; /* Given a node prev_node, insert a new node after the given prev_node */ void insertAfter (Node * prev_node, int new_data) { /*1. check if the given prev_node is NULL */ if (prev_node == NULL) { printf ("the given...

  • 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...

  • in c++ Create a circular, doubly linked list from a file (input.txt), containing a list of...

    in c++ Create a circular, doubly linked list from a file (input.txt), containing a list of names. The number of names is unknown. Prompt the user for the number of nodes to delete and then delete accordingly from the list. Assumption: The number inputted by the user will not exceed the actual number of nodes in the 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...

  • Using the provided Linked List example code, linkedlist.c, as an example Make a node struct that...

    Using the provided Linked List example code, linkedlist.c, as an example Make a node struct that holds ints instead of strings. In your main, insert 25 to 75 random integers with range (0 to 100) into a linked list of your nodes. Use a random to determine how many to make. Write a function int sum(NodePointer current) that returns the sum of the integers in the list by looping through the linked list. Write a function int count(NodePointer current) that...

  • 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...

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