Bağlı Liste Döngülü Örnek

// döngü ile 5 nodelik bir bağlı liste oluşturalım.
// her bir node birbirini göstersin.
// en son node null yani boşluğu göstersin.
// root işaretçisi dizinin başını göstersin.
// tüm diziyi döngü ile yazdıralım.
#include <stdio.h>
#include<stdlib.h>

struct n {
int x;
n * next;
};

typedef n node;

main()
{
node * root; // root işaretçisi tanımlandı.
node * iter;

root = (node *) malloc(sizeof(node)); // ilk hücreyi root gösterdi.
root->x=0;
iter = root;
for(int i=0;i<5;i++)
{
iter->next =(node *) malloc(sizeof(node));
iter->x=i;
iter = iter->next;
}
iter=root;
for(int i=0; i<5;i++){
printf("\n %d \n", iter->x);
iter = iter->next;
}

}

İlk yorum yapan olun

Bir yanıt bırakın

E-posta hesabınız yayımlanmayacak.


*