Загрузка данных


lass Node:
    def __init__(self):
        sefl.val = None
        self.next = None

class Linked_list:
    def __init__(self,lst = []):
        self.size = len(lst)
        if not lst:
            self.head = None
            
            return
    
        self.head = Node(lst[0])
        cur = self.head
        for i in range(1, len(lst[i])):
            cur.next = Node(lst[i])
            cur = cur.next

    def __len__(self):
        return self.size


    def __str__(self):
        a = " "
        cur = self.head
        while cur.next:
            a += f'{cur.val}->'
            cur = cur.next
    
        return a        

    

    def pop(self, idx):
        if idx > self.size - 1:
            raise IndexError(f"index out of range")
        if idx < 0:
            raise IndexError(f"negative index")
        if idx == 0:
            taret = self.head
            self.head = self.head.next
            self.size -=1
            return target.val
        
        
        cur = self.head
        cur_idx = 0
        
        while car_idx != idx - 1:
            cur = cur.next
            cur_idx += 1
        target = cur.next
        tmp = cur.next.next
        cur.next = tmp
        self.size -= 1
        return target.val
    
         
        def is_empty(self):
            return self.head == None
        
        def __getitem__(self, idx):
            if ixd > self.size - 1:
                raise IndexError(f"out of range inx")
            
            cur = self.head
            ctr = 0
            
            while car_idx != idx - 1: 
                cur = cur.next
                ctr += 1
            return cur.val
        
        
        def __setitem__(self):
            return
        
        
        
        def __append__():
            
        
a = Linked _list([1,2,3,4])
print(a.pop)
print(a)