1)     Create a linked list by selecting the appropriate choices from the menu. The input integer values to your program will be distinct.  Add a method, “public void printAllPrimes()” in LinkedList.java which prints all the “data” values in the list that are prime. If there are no prime numbers in the list, the program should output, “No prime numbers in the list”. Finally, add a choice in the menu to call the above method upon user selection.

 Example:

Starting List:    12 --> 2 --> 44 --> 67 --> 21

The prime numbers in the list are:

2

67

 

2)     Create a linked list by selecting the appropriate choices from the menu. The input integer values to your program will be distinct.

Add a method, “public void moveInputValueToFront (int x)” in LinkedList.java which implements the following:

·        Search for x in the list, L:

 If x is not found in L:

·        Create a new node (data value = x) and insert the node at the front of L.

 Else    // x is found in L

·        If x is contained in the front node of L, simply print L.

Else // x is elsewhere in L

o   Remove the node which contains x and insert it at front of L.

 

Finally, add a choice in the menu to call the above method upon user selection.

Program Output:

Starting List:    12 --> 2 --> 44 --> 67 --> 21

Input value, x?

121

121 is not in the list

Adding 121 to the front of the list

List:  121 -> 12 --> 2 --> 44 --> 67 --> 21

Input value, x?

44

List:  44 -->121 --> 12 --> 2 --> 67 --> 21

 

3)     Another version of the insertion sort algorithm is as follows (we will use linked lists for this problem):

Take input values one at a time and insert them in the appropriate place in the list. Hence, at each stage, the printed linked list is sorted (increasing/decreasing order). Print your list after every insertion of the input. You can assume that the input values in the list will be distinct integers.

Example:

Input your value:  6

The List so far: 6

Input your value:  12

The List so far:  6 12

Input your value:  1

The List so far: 1 6 12

Input your value:  11

The List so far: 1 6 11 12

Input your value:  0

The List so far:  0 1 6 11 12

 

4)     Re-write the bubble and selection sorting algorithms using a singly linked list. (Solution for Bubble Sort)

 

5)     Merge two input sorted, singly linked lists of unequal lengths into a single sorted list.

 

6)     Implement a circular linked list (which is a singly linked list whose last node is connected to its first node).

 

7)     A doubly linked list a linked list where each node stores the reference to the next node and the previous node.

a.     Create and print a doubly linked list.

b.     Write the methods that were described in the above Example Programs, #1, #2 and #3 for a doubly linked list.

 

8)     Stanford CS Library: Linked Lists Problem Set