Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a new instance method for the linked list implementation of the MyLinkedList class called switchFirstWithLast. SwitchFirstWithLast switches the first node of a list with

Write a new instance method for the linked list implementation of the MyLinkedList class called switchFirstWithLast. SwitchFirstWithLast switches the first node of a list with the last node of another list. For example, if list1 contains the elements a, c, d, r, t and list2 contains: *, &, 6, x, b, then the call

list1.switchFirstWithLast (list2);

would leave list1 with the elements b, c, d, r, t

and list2 with the elements *, &, 6, x, a

Write the implementation code for the method SwitchFirstWithLast taking into consideration that MyLinkedList class have nodes which are instances of the following class:

class Node{

public Object data;

public Node next;

public Node(Object o){

data = o;

}

}

And MyLinkedList class have a public head attribute which is a reference to the first node and a public size attribute which is a count of nodes in the linked list and the following methods are already there:

  1. Two contructors
  2. boolean add(Object o, int index) // adds a node at a specific index. If index <0 or index> size the method returns false and returns true otherwise.
  3. boolean remove(Object o)// removes the first existence of the node containing data equal to o. if no node contains a value equal to o the method returns false.

Important Notes:

  1. you are not allowed to define any helper methods.
  2. MyLinkedList class does not have a tail attribute (reference to the last node).

in java

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

Upgrading Oracle Databases Oracle Database New Features

Authors: Charles Kim, Gary Gordhamer, Sean Scott

1st Edition

B0BL12WFP6, 979-8359657501

More Books

Students also viewed these Databases questions

Question

Discuss succession planning. How does it help organizations?

Answered: 1 week ago