Question: Please include a main class. Question 1 : Write a method in the DoublyLinkedList class ( name it isSorted ) to check if the list
Please include a main class. Question :
Write a method in the DoublyLinkedList class name it isSorted to check if the list is sorted or not..
Question :
Write a method in the DoublyLinkedList class name it removeAll to remove ALL occurrences of an element to end of linked list.
Question :
Write a method in the DoublyLinkedList class name it moveLastToFront to move the last element of Linked List to front. public class DoublyLinkedList
Node head;
Node last;
public DoublyLinkedList
head null;
last null;
public boolean isEmpty
return head null;
public int size
int count ;
Node p head;
while p null
count;
p pnext;
return count;
public void addString e
if isEmpty
head new Nodee null, null;
last head;
else
last.next new Nodee null, last;
last last.next;
public void addint index, String e
if index index size
throw new IndexOutOfBoundsException;
if index
Node p head;
head new Nodee p null;
if p null
pprev head;
if last null
last head;
return;
Node pred head;
for int k ; k index; k
pred pred.next;
Node succ pred.next;
Node middle new Nodee succ, pred;
pred.next middle;
if succ null
last middle;
else
succ.prev middle;
public String removeint index
String element;
if index index size
throw new IndexOutOfBoundsException;
if index
element head.element;
head head.next;
if head null
last null;
return element;
if index size
Node pred head;
for int k ; k index ; k
pred pred.next;
element pred.next.element;
pred.next pred.next.next;
if prednext null
last pred;
return element;
else
Node pred head;
for int k ; k index; k
pred pred.next;
element pred.next.element;
pred.next pred.next.next;
pred.next.prev pred;
if prednext null
last pred;
return element;
public String toString
String result ;
Node current head;
while current null
result current.element;
if currentnext null
result ;
current current.next;
result ;
return result;
public void clear
head null;
last null;
public void getElementint index
if index index size
Node current head;
for int i ; i index; i
current current.next;
public boolean containsString value
int index ;
Node current head;
while current null
if currentelement.equalsvalue
return true;
index;
current current.next;
return false;
public int IndexOfString value
int index ;
Node current head;
while current null
if currentelement.equalsvalue
return index;
index;
current current.next;
return ;
public void allIndexesOfString value
List indexes new ArrayList;
Node current head;
int index ;
while current null
if currentelement.equalsvalue
indexes.addindex;
current current.next;
index;
public void print
Node ref head;
while ref null
System.out.printlnrefelement;
ref ref.next;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
