Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Apr 2017 |
Last Sign in: | 12 Weeks Ago, 5 Days Ago |
Questions Answered: | 4870 |
Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Please do write the code in javaModify the author's "MyLinkedList" class to add the following methods: a. swap receives two index positions as parameters, and swaps the nodes at these positions by changing the links, provided both positions are within the current size b. shift receives an integer (positive or negative) and shifts the list this many positions forward (if positive) or backward (if negative). 1,2,3,4 shifted +2 3,4,1,2 1,2,3,4 shifted -1 4,1,2,3 c. erase receives an index position and number of elements as parameters, and removes elements beginning at the index position for the number of elements specified, provided the index position is within the size and together with the number of elements does not exceed the size d. insertList receives another MyLinkedList and an index position as parameters, and copies the list from the passed list into the list at the specified position, provided the index position does not exceed the size. e. main add code to the main method to demonstrate each of your methods
Â
/*** LinkedList class implements a doubly-linked list.*/public class MyLinkedList<AnyType> implements Iterable<AnyType>{/*** Construct an empty LinkedList.*/public MyLinkedList( ){clear( );}/*** Change the size of this collection to zero.*/public void clear( ){beginMarker = new Node<AnyType>( null, null, null );endMarker = new Node<AnyType>( null, beginMarker, null );beginMarker.next = endMarker;theSize = 0;}/*** Returns the number of items in this collection.* @return the number of items in this collection.*/public int size( ){return theSize;}public boolean isEmpty( ){return size( ) == 0;}/*** Adds an item to this collection, at the end.* @param x any object.* @return true.*/public boolean add( AnyType x ){add( size( ), x );return true;}/*** Adds an item to this collection, at specified position.* Items at or after that position are slid one position higher.* @param x any object.* @param idx position to add at.* @throws IndexOutOfBoundsException if idx is not between 0 and size(),inclusive.*/public void add( int idx, AnyType x ){addBefore( getNode( idx, 0, size( ) ), x );}/**