Submission
Due Dates
Create a linked list by selecting the appropriate choices from the menu in TestLinkedList.java. The input values to your program need not be distinct. Your program has to remove all the nodes in the linked list whose data values contain the maximum value (as computed in the original list).
Linked Lists
1 - Insert At Back
2 - Insert At Front
3 - Remove From Front
4 - Remove From Back
5 - Remove All Max
6 - Quit
> 1
Enter the value?
> 23
The values so far in the list:
23
1 - Insert At Back
2 - Insert At Front
3 - Remove From Front
4 - Remove From Back
5 - Remove All Max
6 - Quit
> 1
Enter the value?
> 2
The values so far in the list:
23 --> 2
1 - Insert At Back
2 - Insert At Front
3 - Remove From Front
4 - Remove From Back
5 - Remove All Max
6 - Quit
> 2
Enter the value?
> 567
The values so far in the list:
567 --> 23 --> 2
1 - Insert At Back
2 - Insert At Front
3 - Remove From Front
4 - Remove From Back
5 - Remove All Max
6 - Quit
> 1
Enter the value?
> 567
The values so far in the list:
567 --> 23 --> 2 --> 567
1 - Insert At Back
2 - Insert At Front
3 - Remove From Front
4 - Remove From Back
5 - Remove All Max
6 - Quit
> 1
Enter the value?
> 32
The values so far in the list:
567 --> 23 --> 2 --> 567 --> 32
1 - Insert At Back
2 - Insert At Front
3 - Remove From Front
4 - Remove From Back
5 - Remove All Max
6 - Quit
> 5
The values so far in the list:
23 --> 2 --> 32
1 - Insert At Back
2 - Insert At Front
3 - Remove From Front
4 - Remove From Back
5 - Remove All Max
6 - Quit
> 6
End of Program
The values so far in the list:
23 --> 2 --> 32
Create a linked list by selecting the appropriate choices from the menu in TestLinkedList.java. The input values to your program will be distinct. Your program has to remove all the nodes in the list whose data values are non-prime.
Include the following method in LinkedList.java to check if an integer (> 1) is prime or non-prime:
public boolean isPrime(int p) {
int i = 2;
boolean m = true;
if (p == 1 || p == 0) {
return false;
} else {
while (i < p && m == true) {
if (p % i == 0) {
m = false;
} else {
i++;
}
}
return m;
}
}
Linked Lists
1 - Insert At Back
2 - Insert At Front
3 - Remove From Front
4 - Remove All Max
5 - Remove All Non-Primes
6 - Quit
> 1
Enter the value?
> 12
The values so far in the list:
12
1 - Insert At Back
2 - Insert At Front
3 - Remove From Front
4 - Remove All Max
5 - Remove All Non-Primes
6 - Quit
> 2
Enter the value?
> 15
The values so far in the list:
15 --> 12
1 - Insert At Back
2 - Insert At Front
3 - Remove From Front
4 - Remove All Max
5 - Remove All Non-Primes
6 - Quit
> 1
Enter the value?
> 23
The values so far in the list:
15 --> 12 --> 23
1 - Insert At Back
2 - Insert At Front
3 - Remove From Front
4 - Remove All Max
5 - Remove All Non-Primes
6 - Quit
> 1
Enter the value?
> 31
The values so far in the list:
15 --> 12 --> 23 --> 31
1 - Insert At Back
2 - Insert At Front
3 - Remove From Front
4 - Remove All Max
5 - Remove All Non-Primes
6 - Quit
> 5
The values so far in the list:
23 --> 31
1 - Insert At Back
2 - Insert At Front
3 - Remove From Front
4 - Remove All Max
5 - Remove All Non-Primes
6 - Quit
> 6
End of Program
The values so far in the list:
23 --> 31
Write a program which implements the following:
insertAtFront(int val)
or insertAtBack(int val)
.Insert Before
in LinkedListTest.java.insertBeforeValue(int x, int y)
in LinkedList.java.// Code for menu choice (Part B)
System.out.println("Value to insert?");
int value = scanner1.nextInt();
System.out.println("Insert Before?");
int before = scanner1.nextInt();
list.insertBeforeValue(before, value);
// Code for insertBeforeValue (Part C)
public void insertBeforeValue(int x, int y) {
Node ad = getBeforeReference(x); // Searches the list for “x”.
// If there is a node whose data value is same as “x”,
// returns the reference of this node. Otherwise, returns null.
// If “ad” is “null”, the method creates a new node whose data
// value is the value in the variable, “x” and inserts this
// new node at the end of the list.
// If “ad” is not “null”, the method creates a new node whose
// data value is the value in the variable, “x” and inserts
// this new node before the node whose data value is “y”.
}
Linked Lists
1 - Insert At Front
2 - Insert At Back
3 - Insert Before
4 - Quit
> 1
Value to insert?
> 12
The values so far in the list:
12
1 - Insert At Front
2 - Insert At Back
3 - Insert Before
4 - Quit
> 1
Value to insert?
> 15
The values so far in the list:
15 --> 12
1 - Insert At Front
2 - Insert At Back
3 - Insert Before
4 - Quit
> 3
Value to insert?
> 13
Insert Before?
> 12
The values so far in the list:
15--> 13 --> 12
1 - Insert At Front
2 - Insert At Back
3 - Insert Before
4 - Quit
> 3
Value to insert?
> 21
Insert Before?
> 15
The values so far in the list:
21--> 15 --> 13 --> 12
1 - Insert At Front
2 - Insert At Back
3 - Insert Before
4 - Quit
> 4
End of Program
The values so far in the list:
21--> 15 --> 13 --> 12