Script that tests the behavior of linked lists in Python.
Created for the course Data Structures and Algorithms I at EAFIT University.
- Links the functions and classes of
linkedLists.py
with your main file - Prints your linked list in the console
- Create a linked list from scratch and see the output from your modifications
In /examples
path you will find some implementations.
There is also a template.py
to adapt your main file.
Clone the script linkedLists.py
on your work folder (where your main file is).
Do not modify the script. All the tests will actually be within your main file.
- Import the classes and functions of
linkedLists.py
on your main file:
from linkedLists import *
- Code the function you want to test on your main file:
def insertarAlInicio(head: Node, valor: int) -> Node:
nuevoNodo = Node(valor)
nuevoNodo.next = head
return head
- In the
main()
function, create the tests to check for.
The insertAtEnd(head, val)
function (from the script) creates the Nodes of your original linked list
Remember to assign the values to the head of the linked list. Also, it must begin with head = None
.
def main():
head = None
head = insertAtEnd(head, 1)
head = insertAtEnd(head, 2)
head = insertAtEnd(head, 99)
head = insertAtEnd(head, 4)
head = insertAtEnd(head, 5)
# 5->4->99->2->1->None
head = insertarAlInicio(head, 1)
When you are going to use your function, assign the head again, depending on the behavior of the function that you created. If the function return a Node or a head, you have to assign this function to the head again. If the function return a value like a number or another thing different from a Node, you have to put the function inside a print to see the result. This will depend on your necessities.
- Run the
printll(head)
function to print your modified linked list.
printll(head)
# PENDING: OUTPUT AFTER
Pull requests are welcome. I will take a look at them.