Question: In python I need help fixing my linked list since it doesn't seem to be working and using the same methods to create a doubly
In python
I need help fixing my linked list since it doesn't seem to be working and using the same methods to create a doubly linked list
here's my code so far, thank you!! :)
# Implementing the node class class Node: def __init__(self, data = None, nextNode = None): self.data = data self.nextNode = nextNode def __str__(self): return str(self.data) def getData(self): return self.data def getNext(self): return self.nextNode
def setNext(self,newNext): self.nextNode = newNext # Implementing the linked lists class linkedLists: def __init__(self, head = None): self.head = None
def add(self, data): newNode = Node(data) if(self.head): newNode.setNextNode = self.head self.head = newNode else: self.head = newNode
def remove(self,data): current = self.head previous = None found = False while not found: if current.getData() == data: found = True else: previous = current current = current.getnextNode() if previous == None: self.head = current.getnextNode() else: previous.nextNode(current.getnextNode())
def size(self): current = self.head count = 0 while current != None: count = count + 1 current = current.getNext() return count
def search(self,data): current = self.head found = False while current != None and not found: found = True else: current = current.getnextNode() return found def insert(self,data): newNode = Node(data) newNode.setNext(self.head) self.head = newNode
def isEmpty(self): return self.head == None
def append(self):
# Big O run time:
#Implementing Doubly-Linked List class Node: def __int__(delf, data): self.data = data self.previous = None self.next = None
class doublyLinked: def __init__(self): self.head = None self.tail = None
def addNode(self, data): newNode = Node(data)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
