30 Day code challenge-python
Day 15–Linked List
Task:
Complete the insert function in your editor so that it creates a new Node (pass data as the Node constructor argument) and inserts it at the tail of the linked list referenced by the head parameter. Once the new node is added, return the reference to the head node.
Input Format
The first line contains T, the number of elements to insert.
Each of the T next lines contains an integer to insert at the end of the list.
Output Format
Return a reference to the head node of the linked list.
Explanation
Line 22–28: The class is called and the functions inside the class are executed based on the user input.
Line 12–21: If the head of the List is null then, the current node becomes the head. Else, next node becomes current node, new node becomes next node.
Line 5–10: Prints the data stored in the Linked List.
Bonus Tip: In Linked List current node stores the next node address. Whereas, In Doubly Linked List node stores next node and previous node address.
See you on day 16