Skip to main content

A Python implementation of a singly linked list

Project description

Singly Linked List

This is a Python implementation of a singly linked list.

Usage

Singly Linked List

This is a Python implementation of a singly linked list.

Installation

Install the SingleLinkedList package from PyPI using pip:

pip install single-linked-list==0.0.3

then, import the SingleLinkedList class or CicruleSingeLinkedList

from slll.slll import SingleLinkedList
from slll.csll import CicruleSingeLinkedList

Initialize a Singly Linked List

single_linked_list = SingleLinkedList()
cicrule_single_list = CicruleSingeLinkedList()

Methods

* Append

  • inserts a new node at the end of the linked list.

Method:

  • append(data)

data(any) : The data to be stored in the new node.

single_linked_list.append(1)
single_linked_list.append(2)
cicrule_single_list.append(1)
cicrule_single_list.append(2)

* Preappend

  • inserts a new node at the beginning of the linked list.

Method:

  • pre_append(data)

data(any) : The data to be stored in the new node.

single_linked_list.pre_append(0)
cicrule_single_list.pre_append(0)

* Insert

  • inserts a new node at the specified index in the linked list.

Method:

  • insert(data, index)

index(int) : The index where the new node should be inserted. data(any) : The data to be stored in the new node.

single_linked_list.insert(2, 3)
cicrule_single_list.insert(2, 3)

* Find

  • returns the index of the first node containing the specified data.

Method:

  • find(data)

data(any): The data to search for.

index = single_linked_list.find(2)
index = cicrule_single_list.find(2)
print(index)  # Output: 1

* Get

  • returns the node at the specified index.

Method:

  • get(index)

index(int) : The index of the desired node.

node = single_linked_list.get(2)
node = cicrule_single_list.get(2)
print(node.data)  # Output: 3

* Set

  • updates the data of the node at the specified index.

Method:

  • set(index, data)

index(int) : The index of the node to be updated. data(any) : The new data to be stored in the node.

single_linked_list.set(0, 9000)
cicrule_single_list.set(0, 9000)

* Pop

  • removes and returns the last node in the linked list.

Method:

  • pop()
last_node = single_linked_list.pop()
last_node = cicrule_single_list.pop()
print(last_node)  # Output: 3

* Pop First

  • removes and returns the first node in the linked list.

Method:

  • pop_first()
first_node = single_linked_list.pop_first()
first_node = cicrule_single_list.pop_first()
print(first_node)  # Output: 0

* Remove

  • removes the node at the specified index from the linked list.

Method:

  • remove(index)

index(int) : The index of the node to be removed.

single_linked_list.remove(2)
cicrule_single_list.remove(2)

* Clear

  • clears all nodes in the linked list.

Method:

  • clear()
single_linked_list.clear()
cicrule_single_list.clear()

* Get Length

  • returns the current size (length) of the linked list.

Method:

  • len()
length = len(single_linked_list)
length = len(cicrule_single_list)
print(length)  # Output: 1

* Traverse and print

  • traverses the linked list and prints the data of each node.

Method:

  • traverse()
single_linked_list.traverse()
cicrule_single_list.traverse()
# Output: 0 -> 1 -> 3

* String representation

  • returns a string representation of the linked list.

Method:

  • str()
linked_list_str

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

single-linked-list-0.0.3.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

single_linked_list-0.0.3-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file single-linked-list-0.0.3.tar.gz.

File metadata

  • Download URL: single-linked-list-0.0.3.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for single-linked-list-0.0.3.tar.gz
Algorithm Hash digest
SHA256 4a549fac6fc94c0267df283bd5444ea067a17779edb62631804abf491b617a80
MD5 94e419265fdf73369b1c677c2de563ed
BLAKE2b-256 b57d0d81ed45cc598195d75ad108109476bbba6d56bf1a220f8641da525b4694

See more details on using hashes here.

File details

Details for the file single_linked_list-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for single_linked_list-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 19c80f736df13bde4a535eff74a13ce2b9d91810c2bddd0876549e6282faf6b1
MD5 63b898dcf66bf700b9a548344d87d47e
BLAKE2b-256 fe130b05a307273e9cd8424615b458c98cd5d812d8f943701b90b2c838bcaa08

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page