Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

9. Figure 2 shows the structure of a Doubly linked list. (no duplicates) prev next size: number of nodes header trailer Figure 2 Structure of

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
9. Figure 2 shows the structure of a Doubly linked list. (no duplicates) prev next size: number of nodes header trailer Figure 2 Structure of a Doubly Linked List This doubly linked list has header and trailer nodes. The variable size stores the number of nodes in this list. Each node has an integer element, next and prev reference. (You do not know the current sta of this list! Assume that we defined a Node class already You can use statement below to allocate a new node named newest whose element is 100, next is null and prev is null. Node newest new Node ("100") Please write methods to accomplish following operations. (6 points) Write a method, addBetween, to handle the general case of an insertion between the two nodes. a) private void addBetween int newElement, Node predecessor, Node successor) b) (6 points) Write a method, remove, to handle the general case of a deletion of a given node. private Node remove(Node node) nsert a new node at the head by calling the addBetween method. d) (5 points) Delete the last node by calling the remove n ethod c) (6 points) Search a node according to a given key (Extra 7 points) Insert a new node with newElement after a given node with the key by calling the search and addBetween method. public Node addAfter(int key, int newElement) g) (Extra 7 points) Delete a given node according a given key by calling search and method. ove Thi tur public Node removeAt(int key) f g) (Extra 7 points) Delete a given node according a given key by calling search and search and remove u Thi method. public Node removeAt(int key)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

4th Edition

0619064625, 978-0619064624

More Books

Students also viewed these Databases questions