Quick actions

cmd+k|ctrl+k

Navigation

Languages

myLinkedList

Snippet info

Language

Python

Visibility

public

Author

moin778866.ma

Created

2022-07-30T18:24:00.600079Z

Updated

2022-07-30T18:33:47.504252Z

# creating linked list in python
# 10->3->5
# linked_list = {
#     "head":{
#         "value": 10,
#         "next":{
#             "value":3,
#             "next":{
#                 "value":5,
#                 "next":None,
#             }
#         }
#     }
# }
# print(linked_list["head"]["next"]["next"]["value"])

# ll by oop
class LinkedList:
    def __init__(self, value1, value2, value3):
        self.head ={
                "value": value1,
                "next": {
                    "value": value2,
                    "next":{
                        "value":value3,
                        "next": None
                    }
                }
            
        }
    
    # method to append item at none
    def append(self, item):
        self.head["next"]["next"]["next"] = {
            "value": item,
            "next":None
        }
    def preppend(self, value0):
        self.hero={
            "value":value0,
            "next": self.head
        }
        
        
myLinkedList = LinkedList(12,3,5)
print(myLinkedList.head["next"]["next"]["value"])
myLinkedList.append(88)
print(myLinkedList.head["next"]["next"]["next"]["value"])
myLinkedList.preppend(24)
print(myLinkedList.hero["next"]["value"])
INFO