LinkedList-575


NameLinkedList-575 JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/Saqibs575/LinkedList
SummaryA Python package for LinkedList data structure.
upload_time2023-08-06 12:44:17
maintainer
docs_urlNone
authorSaqib Shaikh
requires_python>=3.6
licenseGNU General Public License v3.0
keywords linkedlist linkedlist linked list linkedlist in python linked list data-structure python package
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## **LinkedList : Simple and efficient way to access LinkedList in python** <br>
[![PyPI version](https://badge.fury.io/py/LinkedList-575.svg)](https://badge.fury.io/py/LinkedList-575) 
[![PyPI](https://img.shields.io/pypi/v/LinkedList-575)](https://pypi.org/project/LinkedList-575/)
[![PyPI - License](https://img.shields.io/pypi/l/LinkedList-575)](https://pypi.org/project/LinkedList_575/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/linkedlist-575)](https://pypi.org/project/LinkedList-575/)
[![PyPI - Status](https://img.shields.io/pypi/status/LinkedList-575)](https://pypi.org/project/LinkedList-575/)

![GitHub](https://img.shields.io/github/license/Saqibs575/LinkedList)
[![GitHub pull requests](https://img.shields.io/github/issues-pr/Saqibs575/LinkedList?label=Pull%20Requests)](https://github.com/Saqibs575/LinkedList/pulls)
[![GitHub issues](https://img.shields.io/github/issues/Saqibs575/LinkedList?label=GitHub%20Issues)](https://github.com/Saqibs575/LinkedList/issues)
[![GitHub closed issues](https://img.shields.io/github/issues-closed/Saqibs575/LinkedList)](https://github.com/Saqibs575/LinkedList/issues?q=is%3Aissue+is%3Aclosed)
[![GitHub last commit](https://img.shields.io/github/last-commit/Saqibs575/LinkedList)](https://github.com/Saqibs575/LinkedList/commits/main)
[![GitHub contributors](https://img.shields.io/github/contributors/Saqibs575/LinkedList)](https://github.com/Saqibs575/LinkedList/graphs/contributors)
[![GitHub code size](https://img.shields.io/github/languages/code-size/Saqibs575/LinkedList)](https://github.com/Saqibs575/LinkedList)
[![GitHub stars](https://img.shields.io/github/stars/Saqibs575/LinkedList)](https://github.com/Saqibs575/LinkedList/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/Saqibs575/LinkedList)](https://github.com/Saqibs575/LinkedList/network)
[![GitHub top language](https://img.shields.io/github/languages/top/Saqibs575/LinkedList)](https://github.com/Saqibs575/LinkedList)

-----------------------------
-----------------------------

## **What is it ?**

The **LinkedList** package offers a robust and efficient implementation of a singly linked list data structure in Python. Unlike raw linked lists, this package provides convenient access to elements using indices, allowing for seamless integration with Python's iterable features, such as for loops and other iterable functions. With this package, you can create linked lists and effortlessly access and modify their elements just like you would with lists or tuples.

The primary goal of this package is to bridge the gap between raw linked lists and Python's built-in data structures, making linked lists as user-friendly and versatile as possible. By using this package, you can harness the power of linked lists while enjoying the familiar functionalities offered by Python's native data structures.

---------------------------
---------------------------

## **Table of Contents**

- [Project Architecture](#architecture)
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
    + [Creating a linked list](#create-linkedlist)
    + [Inserting Elements](#insert-elements)
    + [Printing Liked List](#print-list)
    + [Accessing Elements](#access-elements)
        * [Access Using for Lopp](#access-elements1)
        * [Linked List as an Iterator](#access-elements2)
    + [Updating Elements](#update-elements)
    + [Concatenation of Linked List](#concate-list)
    + [Basic Operations](#basic-operations)
        * [Finding Length](#basic-operations0)
        * [Reversing Linked List](#basic-operations1)
        * [Multiplying and Dividing Linked List with numeric Value](#basic-operations2)
        * [Sorting Linked List](#basic-operations3)
- [Contributing](#contributing)
- [License](#license)

------------------------------
------------------------------


## **Project Architecture** <a name = 'architecture'></a>

```
WORKSPACE /
    |
    |--> LinkedList /
    |     |
    |     |--> __init__.py
    |     |
    |     |--> base_list.py
    |     |
    |     |--> node.py
    |     |
    |     |--> linked_list.py
    |
    |--> tests /
    |     |
    |     |--> linked_list_test.py
    |
    |--> .gitignore
    |
    |--> LICENSE
    |
    |--> logo.png
    |
    |--> README.md
    |
    |--> requirements.txt
    |
    |--> setup.py

```
---------------------------------
---------------------------------

## **Features** <a name = 'features'></a>
Here are some key features of LinkedList provided by this package :
- Create a new linked list.
- Setting element with indexing.
- Print linked list using print function.
- Insert element in an existing linked list.
- Get the length of the linked list and reverse it.
- Sort the linked list in ascending or descending order.
- Delete elements(Nodes) from the linked list (using index).
- Perform concatenation of two or more LinkedLists (using '+').
- Insert element in an existing linked list at any index of linked list.
- Access and update elements using index (Just like noraml list in python).
- Perform element-wise division with a numeric value (for numeric linked list).
- Perform element-wise multiplication with a numeric value (for numeric linked list).

-------------------------------
-------------------------------


## **Installation** <a name = 'installation'></a>

You can install LinkedList package using pip :
```python
pip install LinkedList_575

```

---------------------------------
---------------------------------


## **Usage** <a name = 'usage'></a>

The linked list is present in linked_list.py file of LinkedList package. To use linked list in your project, you needed to import. You can import it as follows ;

```python
from LinkedList.linked_list import LinkedList

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)


---------------------------------
---------------------------------


## **Creating a linked list** <a name = 'create-linkedlist'></a>

Now , let's create an object of linked list using LinkedList module. It will create an empty linked list :

```python
linked_list = LinkedList()

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)

---------------------------------
---------------------------------


## **Inserting Elements** <a name = 'insert-elements'></a>

We have created an empty linked list. Now , we can add elements using `insert()` method :

```python
linked_list.insert(10)         # Append  10 at the end
linked_list.insert(30, 1)      # Inserts 30 at index 1
linked_list.insert(20, 0)      # Inserts 20 at the beginning
linked_list.insert(40,-1)      # Inserts 40 at index -1 (last position)
linked_list.insert(-8,-2)      # Inserts -8 at index -2 (second last position)

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)

------------------------------------
------------------------------------


## **Printing Linked List** <a name = 'print-list'></a>

Now we can print each node of linked_list just using print function :

```python
print(linked_list)          # output : 20 --> 10 --> 30 --> -8 --> 40 --> None

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)

------------------------------------
------------------------------------


## **Accessing Elements** <a name = 'access-elements'></a>

Now we can access each elements of linked_list present at any node using its index(i.e writing index in square braces) as we are accessing in case of normal list in python :

```python
print(linked_list[2])       # Output: 30 (Value at index 2)
print(linked_list[-1])      # Output: 40 (Value of the last element)
print(linked_list[-2])      # Output: -8 (Value of the second last element)
print(linked_list[0])       # Output: 20 (Value at index 0, i.e value of the first element)
print(linked_list[-4])      # Output: 10 (Value at index -4, i.e., value of the fourth last element)
    
```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)

------------------------------------
------------------------------------


### **Access Using for Loop** <a name = 'access-elements1'></a>

```python
n = len(linked_list)        # Getting length of linked_list

for i in range(n) :
    print(linked_list[i])

# output: 
# 20 
# 10 
# 30 
# -8 
# 40

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)

----------------------------------
----------------------------------


### **Linked List as an Iterator** <a name = 'access-elements2'></a>


As we know that it is very convinient to use and access the element of data structure by using for loop. But in case of linked list we can not directly access elements(data present at the node) using for loop. To solve this problem, I have used `__iter__`  and `__next__` dunder method to make it irerable.


```python
for data in linked_list :
    print(data)

# Output:
# 20 
# 10
# 30
# -8
# 40

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)

-----------------------------------
-----------------------------------


## **Updating Elements** <a name = 'update-elements'></a>
Now we can update each elements of linked_list present at any node using its index(i.e writing index in square braces) and assignment as we are updating in case of normal list in python :

```python
linked_list[-1] = 25        # Update element at index -1 (i.e last element) to 25
linked_list[2]  = 50        # Update element at index 2  (i.e third element) to 50
linked_list[0]  = 108       # Update element at index 0  (i.e fist element) to 108
linked_list[-2] = -9        # Update element at index -2 (i.e second last element) to -9
linked_list[-4] = 0         # Update element at index -4 (i.e value of the fourth last element) to 0

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)



Now , let's see the updated linked_list :

```python
print(linked_list)           # output: 108 --> 0 --> 50 --> -9 --> 25 --> None

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)

------------------------------------
------------------------------------


## **Concatenation of Linked List** <a name = 'concate-list'></a>

We can perform concatenation operation of two or more linked lists by just using '+' operator between them, let's see the example ;

```python
linked_list1 = LinkedList()     # Create linked list
linked_list2 = LinkedList()     # Create linked list

# Let's add the elements to both the linked lists
for i in range(6) :
    linked_list1.insert(i , 0)
for i in range(5) :
    linked_list2.insert(-(i+1) , 0)

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)


```python
# Let's print both the linked lists
print('linked_list1 =' ,linked_list1)            # output: linked_list1 = 5 --> 4 --> 3 --> 2 --> 1 --> 0 --> None
print('linked_list2 =' ,linked_list2)            # output: linked_list2 = -5 --> -4 --> -3 --> -2 --> -1 --> None

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)


```python
# Let's perform concatenation of two linked lists linked_list1 and linked_list2
result1 = linked_list1 + linked_list2
result2 = linked_list2 + linked_list1

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)


```python
# Now, let's print concatenated linked list
print('result1 =' , result1)                 # output: result1 = 5 --> 4 --> 3 --> 2 --> 1 --> 0 --> -5 --> -4 --> -3 --> -2 --> -1 --> None
print('result2 =' , result2)                 # output: result2 = -5 --> -4 --> -3 --> -2 --> -1 --> 5 --> 4 --> 3 --> 2 --> 1 --> 0 --> None

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)


```python
# Let's perform concatenation of more than two linked lists
result3 = linked_list1 + linked_list2 + linked_list

# Now, let's print result3
print('result3 =' , result3)                 # output: result3 = 5 --> 4 --> 3 --> 2 --> 1 --> 0 --> -5 --> -4 --> -3 --> -2 --> -1 --> 108 --> 0 --> 50 --> -9 --> 25 --> None

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)

------------------------------------
------------------------------------


## **Basic Operations** <a name = 'basic-operations'></a>

In this section, we will perform some basic operations in linked list like finding length , reversing the node and sorting etc.

## **Finding Length** <a name = 'basic-operations0'></a>

As in case of python list or tuple or any other iterable it is an important task to find the number of elements present in the data structure. As finding the number of elements can be very important insight of data structure like we can iterate over the length and so on. We can find the number of elements by using `len()` funtion and we can pass linked list as as argument. This function `len()` will return the number of elements present in the linked list or we can say that it is a length of linked list.

```python
# Finding length of linked lists
print(len(linked_list ))        # output: 5
print(len(linked_list1))        # output: 6
print(len(linked_list2))        # output: 5
print(len(result1))             # output: 11
print(len(result2))             # output: 11
print(len(result3))             # output: 16

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)

----------------------------------
----------------------------------


## **Reversing Linked List** <a name = 'basic-operations1'></a>
We have performed reverse operations many time in case of python iterables like list or tuple. Similarly, we can use the same function that is `reversed()` to reverse node of linked list. In this function `reverse()` we need to pass linked list as an argument. 

```python
# Reversing nodes of linked lists
print('Before reversing : linked_list =' , linked_list)             # output: Before reversing : linked_list = 108 --> 0 --> 50 --> -9 --> 25 --> None
reversed(linked_list)
print('After reversing : linked_list ='  , linked_list)             # output: After reversing : linked_list = 25 --> -9 --> 50 --> 0 --> 108 --> None
```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)


```python
print('Before reversing : linked_list1 =' ,linked_list1)             # output: Before reversing : linked_list1 = 5 --> 4 --> 3 --> 2 --> 1 --> 0 --> None
reversed(linked_list1)
print('After reversing : linked_list1 ='  ,linked_list1)             # output: After reversing : linked_list1 = 0 --> 1 --> 2 --> 3 --> 4 --> 5 --> None

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)


```python
print('Before reversing : linked_list2 =' ,linked_list2)             # output: Before reversing : linked_list2 = -5 --> -4 --> -3 --> -2 --> -1 --> None
reversed(linked_list2)
print('After reversing : linked_list2 ='  ,linked_list2)             # output: After reversing : linked_list2 = -1 --> -2 --> -3 --> -4 --> -5 --> None

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)


```python
print('Before reversing : result1 ='     , result1)                 # output: Before reversing : result1 = 5 --> 4 --> 3 --> 2 --> 1 --> 0 --> -5 --> -4 --> -3 --> -2 --> -1 --> None
reversed(result1)
print('After reversing : result1 ='      , result1)                 # output: After reversing : result1 = -1 --> -2 --> -3 --> -4 --> -5 --> 0 --> 1 --> 2 --> 3 --> 4 --> 5 --> None

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)


```python
print('Before reversing : result2 ='     , result2)                 # output: Before reversing : result2 = -5 --> -4 --> -3 --> -2 --> -1 --> 5 --> 4 --> 3 --> 2 --> 1 --> 0 --> None
reversed(result2)
print('After reversing : result2 ='      , result2)                 # output: After reversing : result2 = 0 --> 1 --> 2 --> 3 --> 4 --> 5 --> -1 --> -2 --> -3 --> -4 --> -5 --> None

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)


```python
print('Before reversing : result3 ='     , result3)                 # output: Before reversing : result3 = 5 --> 4 --> 3 --> 2 --> 1 --> 0 --> -5 --> -4 --> -3 --> -2 --> -1 --> 108 --> 0 --> 50 --> -9 --> 25 --> None
reversed(result3)
print('After reversing : result3 ='      , result3)                 # output: After reversing : result3 = 25 --> -9 --> 50 --> 0 --> 108 --> -1 --> -2 --> -3 --> -4 --> -5 --> 0 --> 1 --> 2 --> 3 --> 4 --> 5 --> None

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)

------------------------------------
------------------------------------


### **Multiplying and Dividing linked list with numeric value** <a name = 'basic-operations2'></a>
We know that in numpy we can multilpy or divide array(numeric) with any numeric value, as a result the we will get an array in which all the elements of numpy array will be multiplied or divided by the number we have provided. Same operation can be performed on this LinkedList 

```python
# Multiplying Linked List by any numeric value
print('Before multiplication : linked_list =' , linked_list)        # output: Before multiplication : linked_list = 25 --> -9 --> 50 --> 0 --> 108 --> None
linked_list*2
print('After multiplication : linked_list ='  , linked_list)        # output: After multiplication : linked_list = 50 --> -18 --> 100 --> 0 --> 216 --> None

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)


```python
# Dividing Linked List by any numeric value
print('Before division : linked_list =' , linked_list)              # output: After division : linked_list = 50 --> -18 --> 100 --> 0 --> 216 --> None
linked_list / 2
print('After division : linked_list ='  , linked_list)              # output: After division : linked_list = 25.0 --> -9.0 --> 50.0 --> 0.0 --> 108.0 --> None

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)

--------------------------------------
--------------------------------------


### **Sorting Linked Lists**  <a name = 'basic-operations3'></a>
Sorting is one of the most important part in case of oterables. As we have many options to sort LinkedList. But, here we will use merge sort that will provide time complexity of nlog(n) and space complexity is constant.


#### **Sorting Linked Lists in ascending order**

```python
print('Before sorting : linked_list2 =' , linked_list2)              # output: After sorting : linked_list2 = -1 --> -2 --> -3 --> -4 --> -5 --> None
linked_list2.sort()
print('After sorting : linked_list2 ='  , linked_list2)              # output: After sorting : linked_list2 = -5 --> -4 --> -3 --> -2 --> -1 --> None

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)



#### **Sorting Linked Lists in descending order**

```python
print('Before sorting : linked_list1 =' , linked_list1)              # output: After sorting : linked_list1 = 0 --> 1 --> 2 --> 3 --> 4 --> 5 --> None
linked_list1.sort(reverse = True)
print('After sorting : linked_list1 ='  , linked_list1)              # output: After sorting : linked_list1 = 5 --> 4 --> 3 --> 2 --> 1 --> 0 --> None

```
[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)

-------------------------------------
-------------------------------------


## **Contributing** <a name = 'contributing'></a>

Contributions to the LinkedList package are welcome! If you find any bugs or have suggestions for improvement, please open an issue or submit a pull request on GitHub.

-------------------------------------
-------------------------------------


## **License** <a name = 'license'></a>

© 2023 Saqib Shaikh

This package is distributed under the GNU General Public License v3.0 (GPLv3) License. See the [LICENSE](https://github.com/Saqibs575/LinkedList/blob/main/LICENSE) file for more details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Saqibs575/LinkedList",
    "name": "LinkedList-575",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "LinkedList,linkedlist,linked list,linkedlist in python ,linked list data-structure python package",
    "author": "Saqib Shaikh",
    "author_email": "saquibs575@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/8a/72/3d61aa399cba391fa02ef88c123585df40fa8f9eff5e36d90fa8e273a1a6/LinkedList_575-1.0.2.tar.gz",
    "platform": "win32",
    "description": "## **LinkedList : Simple and efficient way to access LinkedList in python** <br>\r\n[![PyPI version](https://badge.fury.io/py/LinkedList-575.svg)](https://badge.fury.io/py/LinkedList-575) \r\n[![PyPI](https://img.shields.io/pypi/v/LinkedList-575)](https://pypi.org/project/LinkedList-575/)\r\n[![PyPI - License](https://img.shields.io/pypi/l/LinkedList-575)](https://pypi.org/project/LinkedList_575/)\r\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/linkedlist-575)](https://pypi.org/project/LinkedList-575/)\r\n[![PyPI - Status](https://img.shields.io/pypi/status/LinkedList-575)](https://pypi.org/project/LinkedList-575/)\r\n\r\n![GitHub](https://img.shields.io/github/license/Saqibs575/LinkedList)\r\n[![GitHub pull requests](https://img.shields.io/github/issues-pr/Saqibs575/LinkedList?label=Pull%20Requests)](https://github.com/Saqibs575/LinkedList/pulls)\r\n[![GitHub issues](https://img.shields.io/github/issues/Saqibs575/LinkedList?label=GitHub%20Issues)](https://github.com/Saqibs575/LinkedList/issues)\r\n[![GitHub closed issues](https://img.shields.io/github/issues-closed/Saqibs575/LinkedList)](https://github.com/Saqibs575/LinkedList/issues?q=is%3Aissue+is%3Aclosed)\r\n[![GitHub last commit](https://img.shields.io/github/last-commit/Saqibs575/LinkedList)](https://github.com/Saqibs575/LinkedList/commits/main)\r\n[![GitHub contributors](https://img.shields.io/github/contributors/Saqibs575/LinkedList)](https://github.com/Saqibs575/LinkedList/graphs/contributors)\r\n[![GitHub code size](https://img.shields.io/github/languages/code-size/Saqibs575/LinkedList)](https://github.com/Saqibs575/LinkedList)\r\n[![GitHub stars](https://img.shields.io/github/stars/Saqibs575/LinkedList)](https://github.com/Saqibs575/LinkedList/stargazers)\r\n[![GitHub forks](https://img.shields.io/github/forks/Saqibs575/LinkedList)](https://github.com/Saqibs575/LinkedList/network)\r\n[![GitHub top language](https://img.shields.io/github/languages/top/Saqibs575/LinkedList)](https://github.com/Saqibs575/LinkedList)\r\n\r\n-----------------------------\r\n-----------------------------\r\n\r\n## **What is it ?**\r\n\r\nThe **LinkedList** package offers a robust and efficient implementation of a singly linked list data structure in Python. Unlike raw linked lists, this package provides convenient access to elements using indices, allowing for seamless integration with Python's iterable features, such as for loops and other iterable functions. With this package, you can create linked lists and effortlessly access and modify their elements just like you would with lists or tuples.\r\n\r\nThe primary goal of this package is to bridge the gap between raw linked lists and Python's built-in data structures, making linked lists as user-friendly and versatile as possible. By using this package, you can harness the power of linked lists while enjoying the familiar functionalities offered by Python's native data structures.\r\n\r\n---------------------------\r\n---------------------------\r\n\r\n## **Table of Contents**\r\n\r\n- [Project Architecture](#architecture)\r\n- [Features](#features)\r\n- [Installation](#installation)\r\n- [Usage](#usage)\r\n    + [Creating a linked list](#create-linkedlist)\r\n    + [Inserting Elements](#insert-elements)\r\n    + [Printing Liked List](#print-list)\r\n    + [Accessing Elements](#access-elements)\r\n        * [Access Using for Lopp](#access-elements1)\r\n        * [Linked List as an Iterator](#access-elements2)\r\n    + [Updating Elements](#update-elements)\r\n    + [Concatenation of Linked List](#concate-list)\r\n    + [Basic Operations](#basic-operations)\r\n        * [Finding Length](#basic-operations0)\r\n        * [Reversing Linked List](#basic-operations1)\r\n        * [Multiplying and Dividing Linked List with numeric Value](#basic-operations2)\r\n        * [Sorting Linked List](#basic-operations3)\r\n- [Contributing](#contributing)\r\n- [License](#license)\r\n\r\n------------------------------\r\n------------------------------\r\n\r\n\r\n## **Project Architecture** <a name = 'architecture'></a>\r\n\r\n```\r\nWORKSPACE /\r\n    |\r\n    |--> LinkedList /\r\n    |     |\r\n    |     |--> __init__.py\r\n    |     |\r\n    |     |--> base_list.py\r\n    |     |\r\n    |     |--> node.py\r\n    |     |\r\n    |     |--> linked_list.py\r\n    |\r\n    |--> tests /\r\n    |     |\r\n    |     |--> linked_list_test.py\r\n    |\r\n    |--> .gitignore\r\n    |\r\n    |--> LICENSE\r\n    |\r\n    |--> logo.png\r\n    |\r\n    |--> README.md\r\n    |\r\n    |--> requirements.txt\r\n    |\r\n    |--> setup.py\r\n\r\n```\r\n---------------------------------\r\n---------------------------------\r\n\r\n## **Features** <a name = 'features'></a>\r\nHere are some key features of LinkedList provided by this package :\r\n- Create a new linked list.\r\n- Setting element with indexing.\r\n- Print linked list using print function.\r\n- Insert element in an existing linked list.\r\n- Get the length of the linked list and reverse it.\r\n- Sort the linked list in ascending or descending order.\r\n- Delete elements(Nodes) from the linked list (using index).\r\n- Perform concatenation of two or more LinkedLists (using '+').\r\n- Insert element in an existing linked list at any index of linked list.\r\n- Access and update elements using index (Just like noraml list in python).\r\n- Perform element-wise division with a numeric value (for numeric linked list).\r\n- Perform element-wise multiplication with a numeric value (for numeric linked list).\r\n\r\n-------------------------------\r\n-------------------------------\r\n\r\n\r\n## **Installation** <a name = 'installation'></a>\r\n\r\nYou can install LinkedList package using pip :\r\n```python\r\npip install LinkedList_575\r\n\r\n```\r\n\r\n---------------------------------\r\n---------------------------------\r\n\r\n\r\n## **Usage** <a name = 'usage'></a>\r\n\r\nThe linked list is present in linked_list.py file of LinkedList package. To use linked list in your project, you needed to import. You can import it as follows ;\r\n\r\n```python\r\nfrom LinkedList.linked_list import LinkedList\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n\r\n---------------------------------\r\n---------------------------------\r\n\r\n\r\n## **Creating a linked list** <a name = 'create-linkedlist'></a>\r\n\r\nNow , let's create an object of linked list using LinkedList module. It will create an empty linked list :\r\n\r\n```python\r\nlinked_list = LinkedList()\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n---------------------------------\r\n---------------------------------\r\n\r\n\r\n## **Inserting Elements** <a name = 'insert-elements'></a>\r\n\r\nWe have created an empty linked list. Now , we can add elements using `insert()` method :\r\n\r\n```python\r\nlinked_list.insert(10)         # Append  10 at the end\r\nlinked_list.insert(30, 1)      # Inserts 30 at index 1\r\nlinked_list.insert(20, 0)      # Inserts 20 at the beginning\r\nlinked_list.insert(40,-1)      # Inserts 40 at index -1 (last position)\r\nlinked_list.insert(-8,-2)      # Inserts -8 at index -2 (second last position)\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n------------------------------------\r\n------------------------------------\r\n\r\n\r\n## **Printing Linked List** <a name = 'print-list'></a>\r\n\r\nNow we can print each node of linked_list just using print function :\r\n\r\n```python\r\nprint(linked_list)          # output : 20 --> 10 --> 30 --> -8 --> 40 --> None\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n------------------------------------\r\n------------------------------------\r\n\r\n\r\n## **Accessing Elements** <a name = 'access-elements'></a>\r\n\r\nNow we can access each elements of linked_list present at any node using its index(i.e writing index in square braces) as we are accessing in case of normal list in python :\r\n\r\n```python\r\nprint(linked_list[2])       # Output: 30 (Value at index 2)\r\nprint(linked_list[-1])      # Output: 40 (Value of the last element)\r\nprint(linked_list[-2])      # Output: -8 (Value of the second last element)\r\nprint(linked_list[0])       # Output: 20 (Value at index 0, i.e value of the first element)\r\nprint(linked_list[-4])      # Output: 10 (Value at index -4, i.e., value of the fourth last element)\r\n    \r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n------------------------------------\r\n------------------------------------\r\n\r\n\r\n### **Access Using for Loop** <a name = 'access-elements1'></a>\r\n\r\n```python\r\nn = len(linked_list)        # Getting length of linked_list\r\n\r\nfor i in range(n) :\r\n    print(linked_list[i])\r\n\r\n# output: \r\n# 20 \r\n# 10 \r\n# 30 \r\n# -8 \r\n# 40\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n----------------------------------\r\n----------------------------------\r\n\r\n\r\n### **Linked List as an Iterator** <a name = 'access-elements2'></a>\r\n\r\n\r\nAs we know that it is very convinient to use and access the element of data structure by using for loop. But in case of linked list we can not directly access elements(data present at the node) using for loop. To solve this problem, I have used `__iter__`  and `__next__` dunder method to make it irerable.\r\n\r\n\r\n```python\r\nfor data in linked_list :\r\n    print(data)\r\n\r\n# Output:\r\n# 20 \r\n# 10\r\n# 30\r\n# -8\r\n# 40\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n-----------------------------------\r\n-----------------------------------\r\n\r\n\r\n## **Updating Elements** <a name = 'update-elements'></a>\r\nNow we can update each elements of linked_list present at any node using its index(i.e writing index in square braces) and assignment as we are updating in case of normal list in python :\r\n\r\n```python\r\nlinked_list[-1] = 25        # Update element at index -1 (i.e last element) to 25\r\nlinked_list[2]  = 50        # Update element at index 2  (i.e third element) to 50\r\nlinked_list[0]  = 108       # Update element at index 0  (i.e fist element) to 108\r\nlinked_list[-2] = -9        # Update element at index -2 (i.e second last element) to -9\r\nlinked_list[-4] = 0         # Update element at index -4 (i.e value of the fourth last element) to 0\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n\r\n\r\nNow , let's see the updated linked_list :\r\n\r\n```python\r\nprint(linked_list)           # output: 108 --> 0 --> 50 --> -9 --> 25 --> None\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n------------------------------------\r\n------------------------------------\r\n\r\n\r\n## **Concatenation of Linked List** <a name = 'concate-list'></a>\r\n\r\nWe can perform concatenation operation of two or more linked lists by just using '+' operator between them, let's see the example ;\r\n\r\n```python\r\nlinked_list1 = LinkedList()     # Create linked list\r\nlinked_list2 = LinkedList()     # Create linked list\r\n\r\n# Let's add the elements to both the linked lists\r\nfor i in range(6) :\r\n    linked_list1.insert(i , 0)\r\nfor i in range(5) :\r\n    linked_list2.insert(-(i+1) , 0)\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n\r\n```python\r\n# Let's print both the linked lists\r\nprint('linked_list1 =' ,linked_list1)            # output: linked_list1 = 5 --> 4 --> 3 --> 2 --> 1 --> 0 --> None\r\nprint('linked_list2 =' ,linked_list2)            # output: linked_list2 = -5 --> -4 --> -3 --> -2 --> -1 --> None\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n\r\n```python\r\n# Let's perform concatenation of two linked lists linked_list1 and linked_list2\r\nresult1 = linked_list1 + linked_list2\r\nresult2 = linked_list2 + linked_list1\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n\r\n```python\r\n# Now, let's print concatenated linked list\r\nprint('result1 =' , result1)                 # output: result1 = 5 --> 4 --> 3 --> 2 --> 1 --> 0 --> -5 --> -4 --> -3 --> -2 --> -1 --> None\r\nprint('result2 =' , result2)                 # output: result2 = -5 --> -4 --> -3 --> -2 --> -1 --> 5 --> 4 --> 3 --> 2 --> 1 --> 0 --> None\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n\r\n```python\r\n# Let's perform concatenation of more than two linked lists\r\nresult3 = linked_list1 + linked_list2 + linked_list\r\n\r\n# Now, let's print result3\r\nprint('result3 =' , result3)                 # output: result3 = 5 --> 4 --> 3 --> 2 --> 1 --> 0 --> -5 --> -4 --> -3 --> -2 --> -1 --> 108 --> 0 --> 50 --> -9 --> 25 --> None\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n------------------------------------\r\n------------------------------------\r\n\r\n\r\n## **Basic Operations** <a name = 'basic-operations'></a>\r\n\r\nIn this section, we will perform some basic operations in linked list like finding length , reversing the node and sorting etc.\r\n\r\n## **Finding Length** <a name = 'basic-operations0'></a>\r\n\r\nAs in case of python list or tuple or any other iterable it is an important task to find the number of elements present in the data structure. As finding the number of elements can be very important insight of data structure like we can iterate over the length and so on. We can find the number of elements by using `len()` funtion and we can pass linked list as as argument. This function `len()` will return the number of elements present in the linked list or we can say that it is a length of linked list.\r\n\r\n```python\r\n# Finding length of linked lists\r\nprint(len(linked_list ))        # output: 5\r\nprint(len(linked_list1))        # output: 6\r\nprint(len(linked_list2))        # output: 5\r\nprint(len(result1))             # output: 11\r\nprint(len(result2))             # output: 11\r\nprint(len(result3))             # output: 16\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n----------------------------------\r\n----------------------------------\r\n\r\n\r\n## **Reversing Linked List** <a name = 'basic-operations1'></a>\r\nWe have performed reverse operations many time in case of python iterables like list or tuple. Similarly, we can use the same function that is `reversed()` to reverse node of linked list. In this function `reverse()` we need to pass linked list as an argument. \r\n\r\n```python\r\n# Reversing nodes of linked lists\r\nprint('Before reversing : linked_list =' , linked_list)             # output: Before reversing : linked_list = 108 --> 0 --> 50 --> -9 --> 25 --> None\r\nreversed(linked_list)\r\nprint('After reversing : linked_list ='  , linked_list)             # output: After reversing : linked_list = 25 --> -9 --> 50 --> 0 --> 108 --> None\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n\r\n```python\r\nprint('Before reversing : linked_list1 =' ,linked_list1)             # output: Before reversing : linked_list1 = 5 --> 4 --> 3 --> 2 --> 1 --> 0 --> None\r\nreversed(linked_list1)\r\nprint('After reversing : linked_list1 ='  ,linked_list1)             # output: After reversing : linked_list1 = 0 --> 1 --> 2 --> 3 --> 4 --> 5 --> None\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n\r\n```python\r\nprint('Before reversing : linked_list2 =' ,linked_list2)             # output: Before reversing : linked_list2 = -5 --> -4 --> -3 --> -2 --> -1 --> None\r\nreversed(linked_list2)\r\nprint('After reversing : linked_list2 ='  ,linked_list2)             # output: After reversing : linked_list2 = -1 --> -2 --> -3 --> -4 --> -5 --> None\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n\r\n```python\r\nprint('Before reversing : result1 ='     , result1)                 # output: Before reversing : result1 = 5 --> 4 --> 3 --> 2 --> 1 --> 0 --> -5 --> -4 --> -3 --> -2 --> -1 --> None\r\nreversed(result1)\r\nprint('After reversing : result1 ='      , result1)                 # output: After reversing : result1 = -1 --> -2 --> -3 --> -4 --> -5 --> 0 --> 1 --> 2 --> 3 --> 4 --> 5 --> None\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n\r\n```python\r\nprint('Before reversing : result2 ='     , result2)                 # output: Before reversing : result2 = -5 --> -4 --> -3 --> -2 --> -1 --> 5 --> 4 --> 3 --> 2 --> 1 --> 0 --> None\r\nreversed(result2)\r\nprint('After reversing : result2 ='      , result2)                 # output: After reversing : result2 = 0 --> 1 --> 2 --> 3 --> 4 --> 5 --> -1 --> -2 --> -3 --> -4 --> -5 --> None\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n\r\n```python\r\nprint('Before reversing : result3 ='     , result3)                 # output: Before reversing : result3 = 5 --> 4 --> 3 --> 2 --> 1 --> 0 --> -5 --> -4 --> -3 --> -2 --> -1 --> 108 --> 0 --> 50 --> -9 --> 25 --> None\r\nreversed(result3)\r\nprint('After reversing : result3 ='      , result3)                 # output: After reversing : result3 = 25 --> -9 --> 50 --> 0 --> 108 --> -1 --> -2 --> -3 --> -4 --> -5 --> 0 --> 1 --> 2 --> 3 --> 4 --> 5 --> None\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n------------------------------------\r\n------------------------------------\r\n\r\n\r\n### **Multiplying and Dividing linked list with numeric value** <a name = 'basic-operations2'></a>\r\nWe know that in numpy we can multilpy or divide array(numeric) with any numeric value, as a result the we will get an array in which all the elements of numpy array will be multiplied or divided by the number we have provided. Same operation can be performed on this LinkedList \r\n\r\n```python\r\n# Multiplying Linked List by any numeric value\r\nprint('Before multiplication : linked_list =' , linked_list)        # output: Before multiplication : linked_list = 25 --> -9 --> 50 --> 0 --> 108 --> None\r\nlinked_list*2\r\nprint('After multiplication : linked_list ='  , linked_list)        # output: After multiplication : linked_list = 50 --> -18 --> 100 --> 0 --> 216 --> None\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n\r\n```python\r\n# Dividing Linked List by any numeric value\r\nprint('Before division : linked_list =' , linked_list)              # output: After division : linked_list = 50 --> -18 --> 100 --> 0 --> 216 --> None\r\nlinked_list / 2\r\nprint('After division : linked_list ='  , linked_list)              # output: After division : linked_list = 25.0 --> -9.0 --> 50.0 --> 0.0 --> 108.0 --> None\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n--------------------------------------\r\n--------------------------------------\r\n\r\n\r\n### **Sorting Linked Lists**  <a name = 'basic-operations3'></a>\r\nSorting is one of the most important part in case of oterables. As we have many options to sort LinkedList. But, here we will use merge sort that will provide time complexity of nlog(n) and space complexity is constant.\r\n\r\n\r\n#### **Sorting Linked Lists in ascending order**\r\n\r\n```python\r\nprint('Before sorting : linked_list2 =' , linked_list2)              # output: After sorting : linked_list2 = -1 --> -2 --> -3 --> -4 --> -5 --> None\r\nlinked_list2.sort()\r\nprint('After sorting : linked_list2 ='  , linked_list2)              # output: After sorting : linked_list2 = -5 --> -4 --> -3 --> -2 --> -1 --> None\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n\r\n\r\n#### **Sorting Linked Lists in descending order**\r\n\r\n```python\r\nprint('Before sorting : linked_list1 =' , linked_list1)              # output: After sorting : linked_list1 = 0 --> 1 --> 2 --> 3 --> 4 --> 5 --> None\r\nlinked_list1.sort(reverse = True)\r\nprint('After sorting : linked_list1 ='  , linked_list1)              # output: After sorting : linked_list1 = 5 --> 4 --> 3 --> 2 --> 1 --> 0 --> None\r\n\r\n```\r\n[CLICK HERE FOR CODE'S OUTPUT](https://github.com/Saqibs575/LinkedList/blob/main/examples.ipynb)\r\n\r\n-------------------------------------\r\n-------------------------------------\r\n\r\n\r\n## **Contributing** <a name = 'contributing'></a>\r\n\r\nContributions to the LinkedList package are welcome! If you find any bugs or have suggestions for improvement, please open an issue or submit a pull request on GitHub.\r\n\r\n-------------------------------------\r\n-------------------------------------\r\n\r\n\r\n## **License** <a name = 'license'></a>\r\n\r\n\u00c2\u00a9 2023 Saqib Shaikh\r\n\r\nThis package is distributed under the GNU General Public License v3.0 (GPLv3) License. See the [LICENSE](https://github.com/Saqibs575/LinkedList/blob/main/LICENSE) file for more details.\r\n",
    "bugtrack_url": null,
    "license": "GNU General Public License v3.0",
    "summary": "A Python package for LinkedList data structure.",
    "version": "1.0.2",
    "project_urls": {
        "Bug Reports": "https://github.com/Saqibs575/LinkedList/issues",
        "Homepage": "https://github.com/Saqibs575/LinkedList",
        "Source": "https://github.com/Saqibs575/LinkedList"
    },
    "split_keywords": [
        "linkedlist",
        "linkedlist",
        "linked list",
        "linkedlist in python ",
        "linked list data-structure python package"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d60fc1ebf0074be75f77d4ec3e93c3fb313f8792ad8da29040fe7c8e1c4f6bb1",
                "md5": "5e3a0e15febbbf02058ae09e4d16cd64",
                "sha256": "284bc598d35dc10eda739b4962a2346e743e07e8bc6fb5e7c0e1f104857f8652"
            },
            "downloads": -1,
            "filename": "LinkedList_575-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5e3a0e15febbbf02058ae09e4d16cd64",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 30493,
            "upload_time": "2023-08-06T12:43:00",
            "upload_time_iso_8601": "2023-08-06T12:43:00.467935Z",
            "url": "https://files.pythonhosted.org/packages/d6/0f/c1ebf0074be75f77d4ec3e93c3fb313f8792ad8da29040fe7c8e1c4f6bb1/LinkedList_575-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8a723d61aa399cba391fa02ef88c123585df40fa8f9eff5e36d90fa8e273a1a6",
                "md5": "91ea17c148d6430df01a4f84b191f9b7",
                "sha256": "7dac463ff745f6dba6f43abdbdfe4f4c8d717f6ec2bdb925693a3b29a902bee9"
            },
            "downloads": -1,
            "filename": "LinkedList_575-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "91ea17c148d6430df01a4f84b191f9b7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 29627,
            "upload_time": "2023-08-06T12:44:17",
            "upload_time_iso_8601": "2023-08-06T12:44:17.945691Z",
            "url": "https://files.pythonhosted.org/packages/8a/72/3d61aa399cba391fa02ef88c123585df40fa8f9eff5e36d90fa8e273a1a6/LinkedList_575-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-06 12:44:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Saqibs575",
    "github_project": "LinkedList",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "linkedlist-575"
}
        
Elapsed time: 0.09452s