Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
This is a Python implementation of a singly linked list.
This is a Python implementation of a singly linked list.
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()
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)
data(any)
: The data to be stored in the new node.
single_linked_list.pre_append(0)
cicrule_single_list.pre_append(0)
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)
data(any)
: The data to search for.
index = single_linked_list.find(2)
index = cicrule_single_list.find(2)
print(index) # Output: 1
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
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)
last_node = single_linked_list.pop()
last_node = cicrule_single_list.pop()
print(last_node) # Output: 3
first_node = single_linked_list.pop_first()
first_node = cicrule_single_list.pop_first()
print(first_node) # Output: 0
index(int)
: The index of the node to be removed.
single_linked_list.remove(2)
cicrule_single_list.remove(2)
single_linked_list.clear()
cicrule_single_list.clear()
length = len(single_linked_list)
length = len(cicrule_single_list)
print(length) # Output: 1
single_linked_list.traverse()
cicrule_single_list.traverse()
# Output: 0 -> 1 -> 3
linked_list_str
FAQs
A Python implementation of a singly linked list
We found that single-linked-list demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.