linked list python module

Solutions on MaxInterview for linked list python module by the best coders in the world

showing results for - "linked list python module"
Tommaso
02 Mar 2019
1class Node:
2    def __init__(self, data = None, next_node = None):
3        self.data = data
4        self.nextNode = next_node
5
6    def get_data(self):
7        return self.data
8
9    def set_data(self, data):
10        self.data = data
11
12    def get_nextNode(self):
13        return self.nextNode
14
15    def set_nextNode(self, nextNode):
16        self.nextNode = nextNode
17
18
19class LinkedList:
20    def __init__(self, head = None):
21        self.head = head
22
23
24    def add_Node(self, data):
25        # if empty
26        if self.head == None:
27            self.head = Node(data)
28
29
30        # not empty
31        else:
32            curr_Node = self.head
33            
34            # if node added is at the start
35            if data < curr_Node.get_data():
36                self.head = Node(data, curr_Node)
37                
38            # not at start
39            else:
40                while data > curr_Node.get_data() and curr_Node.get_nextNode() != None:
41                    prev_Node = curr_Node
42                    curr_Node = curr_Node.get_nextNode()
43
44                # if node added is at the middle
45                if data < curr_Node.get_data():
46                    prev_Node.set_nextNode(Node(data, curr_Node))
47                
48
49                # if node added is at the last
50                elif data > curr_Node.get_data() and curr_Node.get_nextNode() == None:
51                    curr_Node.set_nextNode(Node(data))
52
53
54
55    def search(self, data):
56        curr_Node = self.head
57        while curr_Node != None:
58            if data == curr_Node.get_data():
59                return True
60
61            else:
62                curr_Node = curr_Node.get_nextNode()
63
64        return False
65
66
67    def delete_Node(self, data):
68        if self.search(data):
69            # if data is found
70
71            curr_Node = self.head
72            #if node to be deleted is the first node
73            if curr_Node.get_data() == data:
74                self.head = curr_Node.get_nextNode()
75
76            else:
77                while curr_Node.get_data() != data:
78                    prev_Node = curr_Node
79                    curr_Node = curr_Node.get_nextNode()
80                    
81                #node to be deleted is middle
82                if curr_Node.get_nextNode() != None:
83                    prev_Node.set_nextNode(curr_Node.get_nextNode())
84
85                # node to be deleted is at the end
86                elif curr_Node.get_nextNode() == None:
87                    prev_Node.set_nextNode(None)
88
89        else:
90            return "Not found."
91
92    def return_as_lst(self):
93        lst = []
94        curr_Node = self.head
95        while curr_Node != None:
96            lst.append(curr_Node.get_data())
97            curr_Node = curr_Node.get_nextNode()
98
99        return lst
100
101    def size(self):
102        curr_Node = self.head
103        count = 0
104        while curr_Node:
105            count += 1
106            curr_Node = curr_Node.get_nextNode()
107        return count
108
109      
110## TEST CASES #
111test1 = LinkedList()
112test2 = LinkedList()
113test1.add_Node(20)
114test1.add_Node(15)
115test1.add_Node(13)
116test1.add_Node(14)
117test1.delete_Node(17)
118print(test1.return_as_lst())
119print(test2.size())
Marisa
21 Jun 2016
1pip install llist
queries leading to this page
what are linked lists 3f called in pythonlinked list implementation in pythonlinked list in pylink list in pythonpython linked list methodsimplement a linked list in pythonlinked list in pythonpython linked listpython linked lists tutoriallinked list library in pythonpython library for linked listinbuilt function for head for linked list in pythonlinked list in python tutorialpoinnthow to create a new linked list pythonlinked list operation in pythonlinked lists in python noteswhen to use linked list over python listlinked lsit in pythonlinked list in python3is python list linkedlist implementation in pythonpython linked list head methodlinked lists in python 3create linked list pythonlinked list node in pythonpython new linked listlinked list using pythonsingly linked list pythinpython linked list built indefine linked list in pythonpython traverse a linked listlinked list node class pythonlinked list pthonlinkedlists in pythonlinked list pyrhonpython insert into linked list return whole listhow to do linked list in pythonlinked list in python meaningnext val linkied listlinkedlist pythonpython linked list examplewhat does a linked list output look like in python for testimplementing a linked list in pythonlinkedlist 28 29 function in pyhtonhow to use a linked list in pythonlinked list operations in pythoncreate linkedlist using list pythonlinked lists python 3how to import linked list in pythonlinked lists in python3how to work with linked lists in pythoncreate alinked list inb pyhtonhow to create linked list in pythonlinked lists python3linked list in python 3python program using linked listpython linkedlistpython linked list librarylinked list in pythoondefinition of a function in python linked listwhat does a linked list look like in python linked list pythonsingly linked list pythonpython linked list functionslinked list traversal pythonlinked list in python examplehow to make a linked list in pythondoes python have linked listspython linkedlist librarylinked list in python best explanationshould i do linked list in pythonhow to define a linked list pythonlinked list pythobhow create linked list in pythonpython module for creating linked listlinked list in python implementationsingly linked list program in pythonhow to linked lists together pythonmake linked list in pythonare list in python linked listspython chained linked listlinked list on pythonlinked list setup pythonlinked list implementation in pythonhow do linked lists work in pythontraversing a linked list pythonlinked lists with pythonlinked list pywhat is the linked list in pythonlinked list python in detailcreate a linkedlist in pythonin linked list pythoncreate linked list in pythonpython list is linked listlinked list pyhtonlinked list python librarytraverse linked list in pythonlinked list methods pythoncode for creating linked list in pythonhow to make a linked lit in python with pointershow to create a linked list in python3using linked list directly in pythonlinked list i pythonlinkedinlist python codeself in linkedlist pythonlinked list tutorial pythondoes python use linked listsdoes python have a built in linked listlinkedlists library in pythonpython linked listlinked list example pythonhow to work with linked lists pythonlinked list code in pythonimplementation of all the methods in linkedlist in pythonlinkjed list pythonpython linked list sequencelinked list algorithm in pythonpython linkedlist nodeshow to fail linked list contains in pythonchained list pythonlist python linked listwhat is a linked list pythonlinked listlinked list traversal in pythonlinkedlist in pythonlist to linked list pythonlinkedlist python tutorpython linkeidn list linked list python codelinked list python linked listpopulating an empty linked list in pythonlist node pythoninitilize linked list pythonbuilt in linked list pythonpython linked list how to keep track of headhow to return the head of a linked list in pythonlinked list python implementationpython linked listshow to make linked list on pythonlinked list python example codelinked list in python using listhow to traverse a linked list in pythonlinked list implementation inpythonlinked list pythonhow to values of a linked are in another linked list pythoncreate a linked list pythonbasic linkedlist operations in pythonlinked list python tutoriallistnode in pythonlinked list python3initialize linked list node in pythonlinke list in pythonwhen to use linked list in pythonuses of linkedlist in pythonlinked list pytohn 5dlinked list python programhow to do a linked list in pythonlinked list program in python whole codelinked list pythinlinked list python methodspython inbuilt linkedlistlinked lisy pythonlinked list with pythonsigly linked list in pythonlinked lists python codelinked list implementation pythonlinked list python exampleare linked lists needed in pythoncreate linked list by pythonpython built in linked listimplement linked list in pythonpython lists are linked listslist de link pythonone way linked list pythonimport linked list pythonhow to create linked list in pythonlearn how to implement linked list in pythonlinked list python explainedtraverse linked list pythonlinkelist in pythondefine a loinked list in python linked lists in pythonlinked list package in pythonhow to use linked lists in pythonpython linkedlist implementationpython linked list builtinpython example linkedlisthow to link lists together pythonare python lists linked listslnked list defautl data structrei n pythonlinked list pythonlinked list in pythoinhow to create a node in linked list pythondisplay linked list in pythonlist in python is singly linkedlinked list implementation using pythonis linked list in pythonlinkedin list pythonlinkedin list in pythonpythonn linked listpython create a simple linked listlinked chain implementation in pythonpython linked list implementationpython linkedlist builtpython list or linked listwhat is a linked list pythonhow to define a linked list in python implement linked list pythondata structures and algorithms linked list pythonis list in python a linked listlinkedlist implementtation pythonpython create linked listpython source code linked listlinked list using list in pythonimport linked list pythobnlinkedin python librarypython for in linked listhow to build linked list with a list pythonsingly linked list python examplecan you import a linked list in pythonhow linked list used for in programming in phythonpython linked list standard librarylinled linsertions python algorithmsingle linked list in pythonusing python to define a linked listlinked list python structurequeue linked list pythondo python list act as linked listwhat are linked list pyhtonimplement linkedlist pythonpython linked list exampleswhat are linked lists in pythonis there linked list in pythonaccesing linked list pythonlinklist pythondoubly linked list in pythonlinked llist in pythonlinked list in pytonsingly linked operations in data structure code pythonlinked list pythonlinked lists pythonhow to code a linked list in pythonlinked list python modulelinked list in python with explanationcreate linked list from list pythonpython return linked listhow to display pointers in a linked list in pythonis python list a linked listpython how to create a linked listlist nodes in pythonpython linked list how topython linked code pythonlinked list method in pythonread linked list pythonlinkedlist using pythonimplementing linked list in pythonsingly linked list pythonpy linked listpython library linkedlistis a python list a linked listusing linked list in pythonsyntax of create linked list in pythonlinked list in python useswhat is linked list in pythonlinked list in python libraryhow to make linked lists pythonpython implement linked listpython code linkedlistpython adding t linked listslinked list object pythonimplement a linked list in pythonblinked list python usesadvantages of linked lists in pythonhow to use linked list in pythondefine a linked list in pythonlinkd list pythonlinked list insertions python algorithm in python linked listpython3 linked listhow to make linked list object pythonpython linked list traverse a linked list pythonlinked list program in pythonhow to use builtin linked list in pythonstore a number in linked list pythonhow to create a linked list in pythonpython program for linked listlinked list code pythonpython doubly linked listhowto linked list in python python class linked listunderstanding linked lists pythonhow to create linked list pythonbound to a list python what islinked list all operations in pythonhow to make linked list in pythonare linked lists used in pythoncreation of linked list in pythonlinked list iin pythonpython how to do linked listlinked list python guidesingly linked list using pythonsingle linked list python exampledoes python have a built in linkedlistlinked list sing pythonlinkedlist function in pythonis python list based on linked listlinked list python module