The Reference Program #2 below adds following methods to Reference Program #1:

a)     A boolean method, isEmpty(), which returns true if the list is empty and false if the list is not empty.

b)     A void method, insertAtFront (int input), which inserts the input value at the front of the list.

c)     A void method, removeFromFront(), which removes the front value of the list.

d)     A void method, removeFromBack(), which removes the tail value of the list.

e)     A method to find the maximum value in the linked list. If the maximum value is the last value (tail) in the linked list, it simply prints the list. If the maximum value is the first value (head) or any other value in the list,  it is removed and inserted at the end of the list.

 

 

Reference Program #2

 

Example:

Linked Lists

1 - Insert At Back

2 - Insert At Front

3- Remove From Front

4- Remove From Back

5 - Max to Back

6 - Quit

1

Enter the value?

45

The values so far in the list :

45

 

1 - Insert At Back

2 - Insert At Front

3- Remove From Front

4- Remove From Back

5 - Max to Back

6 - Quit

5

The values so far in the list :

45

 

1 - Insert At Back

2 - Insert At Front

3- Remove From Front

4- Remove From Back

5 - Max to Back

6 - Quit

2

Enter the value?

908

The values so far in the list :

908 --> 45

 

1 - Insert At Back

2 - Insert At Front

3- Remove From Front

4- Remove From Back

5 - Max to Back

6 - Quit

5

The values so far in the list :

45 --> 908

 

1 - Insert At Back

2 - Insert At Front

3- Remove From Front

4- Remove From Back

5 - Max to Back

6 - Quit

1

Enter the value?

190

The values so far in the list :

45 --> 908 --> 190

 

1 - Insert At Back

2 - Insert At Front

3- Remove From Front

4- Remove From Back

5 - Max to Back

6 - Quit

5

The values so far in the list :

45 --> 190 --> 908

 

1 - Insert At Back

2 - Insert At Front

3- Remove From Front

4- Remove From Back

5 - Max to Back

6 - Quit

1

Enter the value?

999

The values so far in the list :

45 --> 190 --> 908 --> 999

 

1 - Insert At Back

2 - Insert At Front

3- Remove From Front

4- Remove From Back

5 - Max to Back

6 - Quit

5

The values so far in the list :

45 --> 190 --> 908 --> 999

 

1 - Insert At Back

2 - Insert At Front

3- Remove From Front

4- Remove From Back

5 - Max to Back

6 - Quit

2

Enter the value?

9999

The values so far in the list :

9999 --> 45 --> 190 --> 908 --> 999

 

1 - Insert At Back

2 - Insert At Front

3- Remove From Front

4- Remove From Back

5 - Max to Back

6 - Quit

5

The values so far in the list :

45 --> 190 --> 908 --> 999 --> 9999

 

1 - Insert At Back

2 - Insert At Front

3- Remove From Front

4- Remove From Back

5 - Max to Back

6 - Quit

6

End of Program

The values so far in the list :

45 --> 190 --> 908 --> 999 --> 9999