Skip to content

This script was created for my Data Structure and Algorithms 1 class, to be able to see how our code works when we modify Linked Lists in Python and understand their behavior.

Notifications You must be signed in to change notification settings

alejoriosm04/linked-list-script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Linked List Script ⛓️

Script that tests the behavior of linked lists in Python.

Created for the course Data Structures and Algorithms I at EAFIT University.

What it does

  • 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

Examples

In /examples path you will find some implementations.

There is also a template.py to adapt your main file.

Step-by-step guide

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.

  1. Import the classes and functions of linkedLists.py on your main file:
from linkedLists import *
  1. 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
  1. 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.

  1. Run the printll(head) function to print your modified linked list.
printll(head)
# PENDING: OUTPUT AFTER

Contribute

Pull requests are welcome. I will take a look at them.

About

This script was created for my Data Structure and Algorithms 1 class, to be able to see how our code works when we modify Linked Lists in Python and understand their behavior.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages