Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
class Node: #class for the single node
def __init__(self, dataval = None):
self.data = dataval #stores the data for the node
self.next = None #stores the reference for the next nodee
self.prev = None #stores the reference for the previous node
class SLinkedList: #class for the double linked list class
def __init__(self):
self.head = None #stores the reference for the node head
self.tail = None #stores the reference for the node tail
def listprint(self): #prints the list
printval = self.head
while printval is not None: #while the printval is not zero prints the values
print (printval.data)
printval = printval.next
def AtBeginning(self,newdata): #adds a new node to the beginning of the list
NewNode = Node(newdata)
def AtEnd(self, newNode): #adds a node to the end of the list
if self.head is None:
self.head = newNode
return
last = self.head
while(last.next):
last = last.next
last.nexts = newNode
list = SLinkedList() #runs the function SLinkedList
list.head = Node("Mon") #the head of the list
#defining the nodes by calling the class Node
e2 = Node("Tue")
e9 = Node("Wed")
e3 = Node("Thur")
e4 = Node("Fri")
e5 = Node("Sat")
e6 = Node("Sun")
list.head.next = e2 #the next node is e2 (after the head Node "Mon")
#defining the next and previous nodes for each node
e2.next = e9
e9.next = e3
e9.prev = e2
e3.prev = e9
e3.next = e4
e4.next = e5
e4.prev = e3
e5.next = e6
e5.prev = e4
e6.prev = e5
list.AtEnd(e5)
#prints the list with all the nodes
list.listprint()