<jupyter_start><jupyter_text>Linked Lists<jupyter_code>import java.util.Random;
import java.lang.*;<jupyter_output><empty_output><jupyter_text>ObjectivesThe objectives of this worksheet are as follows:* Construction of the ListNode class with primative integer as data.* Construct a list by manually setting references* Construct a list by iteratively progressing a reference* Print the contents of a linked list* Understand the general layout of the generic class you will be implementing for lab Using JupyterA few things to remind you with regard to using this Jupyter environment:1. If the platform crashes don't worry. All of this is in the browser so just refresh and all of your changes up to your last save should still be there. For this reason we encourage you to **save often**.2. Be sure to run cells from top to bottom.3. If you're getting weird errors to go: Kernel->Restart & Clear Output. From there, run cells from top to bottom.   ListNode For singly linked lists, each node will contain two items:1. Data associated with a node2. A `next` reference to it's neighbor nodeWith respect to the second category, for a binary tree we will have two references: right and left.**Your Task:** Complete the `ListNode` class such that it has the following two attributes:* a primative integer containing some data* a `next` pointerAdditionally, create a constructor that:* takes a single `int` parameter containing the data for the node we are constructing* sets that data to our data attribute* initializes the `next` references to `null`.For simplicity's sake, keep all attributes at the `public` level of access.<jupyter_code>public class ListNode{
        
    public ListNode(int data){

    }
    
}
// Run this cell to test and see if the 
// TreeNode was sucessfully constructed
ListNode v1 = new ListNode(4);
System.out.printf("Created a ListNode with value: %d\n", v1.data);<jupyter_output><empty_output><jupyter_text>Constructing a List![image.png](attachment:image.png) Now that we have a `ListNode` class, lets use these nodes to create a new `List` class. We will cover later how to create general `List` classees that allow you to dynamically add and remove nodes. For now, this `List` class will construct only a single tree by manually setting the left and right references of nodes.**Your Task**:Our class will only need one attribute, the head of the `List`. To do this follow these steps:1. Set the root equal to a new instance of `ListNode` with the given data.2. Set the root node's next pointer (e.g., `root.next`) to a new instance of `ListNode` with the given data.3. Set the root node's neighbors neighbor (e.g., `root.next.next`) to a new instance of `ListNode` with the given data4. Continue this process for a few steps in order to construct part of the above list.Follow the above pattern to build out the tree in the image.<jupyter_code>public class List{
    
    public ListNode head;
    
    public List(){
        head = new ListNode(12);
        head.next = ??
    }
}
// Run this to test the instantiation of your tree
List myList = new List();<jupyter_output><empty_output><jupyter_text>Displaying a List As our first practice in traversing a list we will print the values of all of the nodes in order. The algorithm, in this case, is as follows:1. Create a reference to the head of the `myList`. This is already taken care of for you.2. While that reference isn't null:    1. print the value of the node at that reference    2. move to the next node by setting the reference to the node refered to by `next`This traversal process will be used again when adding and removing nodes iteratively so keep it in mind.<jupyter_code>public void displayList(){
    
    ListNode tmp = myList.head;
    
    while(??){
        
    }
}<jupyter_output><empty_output><jupyter_text>Now, run the function and see what happens.<jupyter_code>displayList();<jupyter_output><empty_output><jupyter_text>Iteratively Adding a Node As you might have gotten the sense of earlier, manually adding nodes is very tedious and not very functional given we have to manually keep track of how many `.next`s get us to the end of the list. Here we will borrow the traversal process we used when displaying the list to iterate through the list with a few small modifications:1. If the `head` is null then simply set the `head` equal to a new node and return2. Else:    1. Create a new reference to the `head`    2. Iterate until the **reference's next** pointer is null.    3. Set the reference's next pointer equal to a new instance of `ListNode` with the passed in data.    For this worksheet we will only be focusing on the process of adding a node. THe removal process is covered in extensive detail in the mini-assignment's description.<jupyter_code>public class List{
    
    public ListNode head;
    
    public List(){
        head = null;
    }
    
    //Fill in this function
    public void addNode(int data){

    }
    
    public void displayList(){
    
        ListNode tmp = head;

        while(tmp != null){

            System.out.println(tmp.data);
            tmp = tmp.next;

        }
    }
}<jupyter_output><empty_output><jupyter_text>Run the following cell to create a new list and display it's contents.<jupyter_code>List l = new List();
l.addNode(1);
l.addNode(2);
l.addNode(3);
l.displayList();<jupyter_output><empty_output><jupyter_text>Generic List  For the miniassignment you will be implementing a generic, singly linked list. Practice how this class is setup by refactoring your original class to be the new, generic list classes `GList` and `GListNode`. A basic structure for you to fill in is presented below:<jupyter_code>public class GList<E>{

    public class GListNode<E>{
        /* Attributes */
        
    }
    
    public GList(){
    
    }
    
    
    public void addNode(T data){

    }
    
    public void displayList(){
    

    }
}<jupyter_output><empty_output><jupyter_text>Run the following code to ensure you have refactored your original code correctly.<jupyter_code>GList<Integer> l = new GList<>();
l.addNode(1);
l.addNode(2);
l.addNode(3);
l.displayList();<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07164856540768358, 'fraction_numerical': 0.004700923974712271, 'mean_word_length': 3.8620961386918835, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '353901', 'license': 'MIT', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1666, 'n_words': 831, 'path': 'worksheet-3-linked-list.ipynb', 'repo_name': 'CoffeePoweredComputers/487-data-structures-worksheets', 'size': '6169'}