Untitled

mail@pastecode.io avatar
unknown
plain_text
21 days ago
1.1 kB
1
Indexable
Never
class Node:
    def __init__(self, data=None):
        self.data = data
        self.next = None

class SLL:
    def __init__(self):
        self.head = None

    def IAT(self, newdata):
        NewNode = Node(newdata)
        NewNode.next = self.head
        self.head = NewNode

    def RFN(self):
        if not self.head:
            return None
        temp = self.head
        self.head = self.head.next
        temp = None

    def RLN(self):
        if (self.head==None):
            print("Empty")
            return
        curr = self.head
        prev = None
        while curr.next:
            prev = curr
            curr = curr.next
        item = curr.data
        if not prev:
            self.head = None
        else:
            prev.next = None
            curr = None

    def printLL(self):
        temp = self.head
        while temp:
            print(temp.data)
            temp = temp.next

l = SLL()
l.IAT('a')
l.IAT('b')
l.IAT('c')
l.IAT('d')
l.IAT('e')
l.RFN()
l.RLN()
l.printLL()






Leave a Comment