Skip to main content

Singly Linked List in Python

A simple implementation of a singly linked list with various utility functions.

Table of Contents

Installation

You can install the package via pip:

pip install singly_linked_list

Usage

Here’s a quick example of how to use the SinglyLinkList class:

from singly_linked_list import SinglyLinkList

# Create a new linked list
linked_list = SinglyLinkList()

# Add elements
linked_list.push(10)  # Add to front
linked_list.append(20) # Add to end
linked_list.insert(10, 15) # Insert after 10

# Print the list
print(linked_list.printList())  # Output: [15, 10, 20]

# Remove an element
linked_list.remove(10)
print(linked_list.printList())  # Output: [15, 20]

Features

  • Add Nodes: push(data), append(data), insert(after_element, data)
  • Remove Nodes: remove(element), delete()
  • Search: search(key), count(key)
  • Traversal: printList(), length(), getNth(n), getNthFromLast(n)
  • Utilities: isPalindrome(), checkLoop(), lengthOfLoop(), uniqueSorted()
  • Modify List: reverseList(), segregateEvenOdd()
  • Merging Lists: mergeTwoLists(l1, l2)

API Reference

The SinglyLinkList class provides methods for manipulating linked lists as described in the features section. Each method has its own functionality:

  • Initialization: SinglyLinkList()

  • Add Nodes:

    • push(data): Add a new node at the beginning.
    • append(data): Add a new node at the end.
    • insert(after_element, data): Insert a new node after a specified element.
  • Remove Nodes:

    • remove(element): Remove the first occurrence of an element.
    • delete(): Delete the entire linked list.
  • Traversal and Querying:

    • printList(): Return a list of node values.
    • length(): Return the number of nodes in the list.
    • getNth(n): Get the nth node's data.
    • getNthFromLast(n): Get the nth node's data from the end.
  • Utilities:

    • isPalindrome(): Check if the list is a palindrome.
    • checkLoop(): Check for loops in the list.
    • lengthOfLoop(): Find the length of a loop if it exists.
    • uniqueSorted(): Retrieve unique elements in sorted order.
  • Modify List:

    • reverseList(): Reverse the order of nodes.
    • segregateEvenOdd(): Separate even and odd nodes.
  • Merging Lists:

    • mergeTwoLists(l1, l2): Merge two sorted linked lists.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License.

image

Metadata

Release files for py-linked-list 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-linked-list 1.0.0
File Size Uploaded Provenance
py_linked_list-1.0.0.tar.gz 5.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for py-linked-list 1.0.0
File Interpreter ABI Platform
py_linked_list-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.2 kB

Release files / py_linked_list-1.0.0.tar.gz

Download URL py_linked_list-1.0.0.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9b8838c07aaf6f69d94b93cca5e793f38b59a2cc3c5be9e0ca367d27e5903a07
BLAKE2b-256 checksum
How to use checksums
d6fd1daea6b09872f938d6ebbbbe274fdff0bba2d927a8b74c7d051d456dc3c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.1

Release files / py_linked_list-1.0.0-py3-none-any.whl

Download URL py_linked_list-1.0.0-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
08eb2468ce9fffee7dbba57954e02cf91cb1594e0e603ef0b83392d5b390696f
BLAKE2b-256 checksum
How to use checksums
d9b58cac68330055766dada633b016c56cb95ffc74636c7e02879e6ea77479ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.1

Security for py-linked-list 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page