Bağlantılı Liste Türleri

Bu eğitimde, farklı bağlantılı liste türlerini öğreneceksiniz. Ayrıca, bağlantılı listenin uygulamasını C de bulacaksınız.

Bağlantılı listenin türünü öğrenmeden önce, LinkedList Veri Yapısını bildiğinizden emin olun.

Üç yaygın Bağlantılı Liste türü vardır.

  1. Tek Bağlantılı Liste
  2. Çift Bağlantılı Liste
  3. Dairesel Bağlantılı Liste

Tek Bağlantılı Liste

En yaygın olanıdır. Her düğümün verileri ve bir sonraki düğüme işaretçisi vardır.

Tek bağlantılı liste

Düğüm şu şekilde temsil edilir:

 struct node ( int data; struct node *next; )

Üç üyeli tek bağlantılı bir liste şu şekilde oluşturulabilir:

 /* Initialize nodes */ struct node *head; struct node *one = NULL; struct node *two = NULL; struct node *three = NULL; /* Allocate memory */ one = malloc(sizeof(struct node)); two = malloc(sizeof(struct node)); three = malloc(sizeof(struct node)); /* Assign data values */ one->data = 1; two->data = 2; three->data = 3; /* Connect nodes */ one->next = two; two->next = three; three->next = NULL; /* Save address of first node in head */ head = one;

Çift Bağlantılı Liste

Çift bağlantılı bir listede önceki düğüme bir işaretçi ekliyoruz. Böylece, her iki yönde de gidebiliriz: ileri veya geri.

Çift bağlantılı liste

Bir düğüm şu şekilde temsil edilir:

 struct node ( int data; struct node *next; struct node *prev; )

Üç üyeli çift bağlantılı bir liste şu şekilde oluşturulabilir:

 /* Initialize nodes */ struct node *head; struct node *one = NULL; struct node *two = NULL; struct node *three = NULL; /* Allocate memory */ one = malloc(sizeof(struct node)); two = malloc(sizeof(struct node)); three = malloc(sizeof(struct node)); /* Assign data values */ one->data = 1; two->data = 2; three->data = 3; /* Connect nodes */ one->next = two; one->prev = NULL; two->next = three; two->prev = one; three->next = NULL; three->prev = two; /* Save address of first node in head */ head = one;

Dairesel Bağlantılı Liste

Döngüsel bağlantılı liste, son öğenin ilk öğeye bağlandığı bağlantılı bir listenin bir varyasyonudur. Bu dairesel bir döngü oluşturur.

Dairesel bağlantılı liste

Döngüsel bağlantılı bir liste tek veya çift bağlantılı olabilir.

  • tek bağlantılı liste için, son öğenin sonraki işaretçisi ilk öğeyi gösterir
  • Çift bağlantılı listede, ilk öğenin önceki işaretçisi son öğeyi de gösterir.

Üç üyeli dairesel tek bağlantılı bir liste şu şekilde oluşturulabilir:

 /* Initialize nodes */ struct node *head; struct node *one = NULL; struct node *two = NULL; struct node *three = NULL; /* Allocate memory */ one = malloc(sizeof(struct node)); two = malloc(sizeof(struct node)); three = malloc(sizeof(struct node)); /* Assign data values */ one->data = 1; two->data = 2; three->data = 3; /* Connect nodes */ one->next = two; two->next = three; three->next = one; /* Save address of first node in head */ head = one;

Ilginç makaleler...