Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

sachi_linkedlist

class Node:
    def __init__(self,data=None,next=None):
        self.data=data
        self.next=next
    def __repr__(self):
        return repr(self.data)
class Linkedlist:
    def __init__(self):
        self.head=None
    def __repr__(self):
        li=[]
        curr=self.head
        while(curr):
            li.append(repr(curr))
            curr=curr.next
        return "["+','.join(li)+"]"
    def prepend(self,data):
        self.head=Node(data,self.head)
    def append(self,data):
        curr=self.head
        if not curr:
            self.head=Node(data)
            return
        while(curr):
            if(curr.next==None):
                curr.next=Node(data)
            else:
                curr=curr.next
lst=Linkedlist
lst.prepend(1)
lst.append(2)
lst.append(3)
print(lst)
        
        
            
            

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.