BaşlayınÜcretsiz Başlayın

Removing the first node from a linked list

In the previous exercise, you learned how to insert a node at the beginning of a linked list.

In this exercise, you will prepare the code for the remove_at_beginning() method. To do it, you will need to point the head of the linked list to the next node of the head.

Recall the Node() class:

class Node:
  def __init__(self, data):
    self.data = data
    self.next = None

Bu egzersiz

Data Structures and Algorithms in Python

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • In the remove_at_beginning() method, point the head to the next node of the head.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

class LinkedList:
  def __init__(self):
    self.head = None
    self.tail = None
    
  def remove_at_beginning(self):
    # The "next" node of the head becomes the new head node
    self.____ = ____
Kodu Düzenle ve Çalıştır