Delete by Value in Doubly Linked List in DSA Python - Build from Scratch
Node with attributes data, prev, and next. Then create a class called DoublyLinkedList with an attribute head initialized to None. Add a method append to add nodes to the end. Finally, create a DoublyLinkedList object called playlist and append these songs in order: 'SongA', 'SongB', 'SongC', 'SongD', 'SongE'.Start by defining the Node class with data, prev, and next. Then define DoublyLinkedList with a head attribute and an append method to add nodes at the end. Finally, create the playlist and add the songs in the given order.
song_to_delete and set it to the string 'SongC'.Just create a variable named song_to_delete and assign the string 'SongC' to it.
delete_by_value inside the DoublyLinkedList class that takes value as a parameter. This method should find the first node with data == value and remove it from the list by updating the prev and next pointers. Then call playlist.delete_by_value(song_to_delete) to delete the song.Inside delete_by_value, start from head and move forward until you find the node with the matching value. Then update the prev and next pointers of neighboring nodes to remove it. Handle the case if the node to delete is the head. Finally, call the method with song_to_delete.
print_list inside the DoublyLinkedList class that prints the playlist from head to tail. Each song should be printed followed by ' <-> '. After the last song, print None. Then call playlist.print_list() to display the updated playlist.In print_list, start from head and print each node's data followed by ' <-> '. After the last node, print 'None'. Then call playlist.print_list() to show the updated playlist.