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 1:
Write a method in the DoublyLinkedList class (name it isSorted) to check if the list is sorted or not..
Question 2:
Write a method in the DoublyLinkedList class (name it removeAll) to remove ALL occurrences of an element to end of linked list.
Question 3:
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 =0;
Node p = head;
while (p != null){
count++;
p = p.next; }
return count; }
public void add(String e){
if (isEmpty()){
head = new Node(e, null, null);
last = head;
} else {
last.next = new Node(e, null, last);
last = last.next; }
}
public void add(int index, String e){
if (index 0|| index > size()){
throw new IndexOutOfBoundsException();
}
if (index ==0){
Node p = head;
head = new Node(e, p, null);
if (p != null){
p.prev = head;
}
if (last == null){
last = head;
}
return; }
Node pred = head;
for (int k =1; k index; k++){
pred = pred.next; }
Node succ = pred.next;
Node middle = new Node(e, succ, pred);
pred.next = middle;
if (succ == null){
last = middle;
} else {
succ.prev = middle; }}
public String remove(int index){
String element;
if (index 0|| index >= size()){
throw new IndexOutOfBoundsException();
}
if (index ==0){
element = head.element;
head = head.next;
if (head == null){
last = null;
}
return element;
}
if (index == size()-1){
Node pred = head;
for (int k =1; k = index -1; k++){
pred = pred.next;
}
element = pred.next.element;
pred.next = pred.next.next;
if (pred.next == null){
last = pred;
}
return element;
} else {
Node pred = head;
for (int k =1; k index; k++){
pred = pred.next;
}
element = pred.next.element;
pred.next = pred.next.next;
pred.next.prev = pred;
if (pred.next == null){
last = pred;
}
return element; }}
public String toString(){
String result ="[";
Node current = head;
while (current != null){
result += current.element;
if (current.next != null){
result +=","; }
current = current.next; }
result +="]";
return result; }
public void clear(){
head = null;
last = null; }
public void getElement(int index){
if (index 0|| index >= size()){
Node current = head;
for (int i =0; i index; i++){
current = current.next; }}}
public boolean contains(String value){
int index =0;
Node current = head;
while (current != null){
if (current.element.equals(value)){
return true; }
index++;
current = current.next; }
return false; }
public int IndexOf(String value){
int index =0;
Node current = head;
while (current != null){
if (current.element.equals(value)){
return index; }
index++;
current = current.next; }
return -1; }
public void allIndexesOf(String value){
List indexes = new ArrayList>();
Node current = head;
int index =0;
while (current != null){
if (current.element.equals(value)){
indexes.add(index); }
current = current.next;
index++; }}
public void print(){
Node ref = head;
while (ref != null){
System.out.println(ref.element);
ref = ref.next; }}}
 Please include a main class. Question 1: Write a method in

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!