0Pricing
Zig Academy · Ders

Tek Bağlantılı Liste

Düğümleri, sahipliği ve dolaşmayı öğrenin.

Tek Bağlantılı Liste, CoddyKit'te ücretsiz bir Zig Academy dersidir. Bu, 4 dersinin 2. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Zig Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Zig Academy kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

What a Linked List Is

A singly linked list chains values together: each node holds a value and a pointer to the next node, or null at the end. 🔗

Define the Node

A node is a struct with a value and an optional pointer to the next node. Optional means the last node points at null.

const Node = struct {
    value: i32,
    next: ?*Node,
};

Why the Pointer Is Optional

Using ?*Node lets the chain end safely. There is no need for a special sentinel value to mark the tail.

next: ?*Node

The List Tracks the Head

The list itself just remembers the first node, called the head, plus the allocator that owns every node.

const List = struct {
    head: ?*Node,
    alloc: std.mem.Allocator,
};

Allocate One Node

To add a value, ask the allocator to create a single Node on the heap. This returns a pointer to fresh storage.

const node = try self.alloc.create(Node);

Push to the Front

The cheapest insert is at the head: point the new node at the old head, then make it the new head. This is constant time.

node.* = .{ .value = v, .next = self.head };
self.head = node;

Walk the Chain

To traverse, start at head and follow each next pointer until you reach null. A while loop captures the node nicely.

var cur = self.head;
while (cur) |n| {
    std.debug.print("{d}\n", .{n.value});
    cur = n.next;
}

The Capture Unwraps the Optional

Writing while (cur) |n| runs the body only while cur is non-null, and n is the unwrapped pointer. The loop ends at null.

while (cur) |n| { ... }

You Own Every Node

Each node came from the allocator, so each must be returned. Forgetting even one is a leak the testing allocator will report.

Free the Whole List

Walk the chain in deinit, but grab next before freeing, because the node is gone the moment you destroy it.

var cur = self.head;
while (cur) |n| {
    const nxt = n.next;
    self.alloc.destroy(n);
    cur = nxt;
}

Make It Generic

Wrap Node and List in a type-returning function so the list works for any element type, not just i32.

fn LinkedList(comptime T: type) type {
    return struct {
        const Node = struct { value: T, next: ?*Node };
    };
}

Quick Check

You are freeing a linked list node by node. What must you do before destroying each node?

Recap

Nodes hold a value and an optional next pointer. The list tracks the head and an allocator, pushes to the front, and frees node by node. 🎯

Sıkça Sorulan Sorular

“Tek Bağlantılı Liste” dersi ücretsiz mi?

Evet — “Tek Bağlantılı Liste” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Zig Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Zig Academy kursu toplamda 4 dersten oluşur.

“Tek Bağlantılı Liste” dersinde ne öğreneceğim?

Düğümleri, sahipliği ve dolaşmayı öğrenin. Zig Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Zig Academy öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Zig Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 2. dersidir.

“Tek Bağlantılı Liste” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Zig Academy dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Zig Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Sıfırdan Genel Amaçlı Yığın
  2. Tek Bağlantılı Liste
  3. HashMap ve AutoHashMap Kullanımı
  4. Profil Oluşturma ve Güvenlik Dengeleri
← Zig Academy Sayfasına Dön