linked list

entry6 galeri
    3.
  1. örneğin programın bir kenarına kullanıcı veri girişi yapacak, kaç tane veri gireceğini bilmiyorsunuz bu nedenle bellekte nekadar yer ayıracağınızı da bilemezsiniz, işte bu zamanlarda bağlı listeler veri eklendikçe hafızadan yer alıp uzayıp giderler. aşağıda da kodu bulunuyor.

    #include<stdlib.h>
    #include<stdio.h>
    #include <iostream>

    typedef struct node{
    int info;
    struct node *next;
    }NODE;
    typedef NODE *NODEPTR;



    NODEPTR getnode()
    {
    NODEPTR p;
    p=(NODEPTR)malloc(sizeof(struct node));
    return (p);
    }

    void freenode(NODEPTR p)
    {
    free(p);
    }

    void displayList(NODEPTR p)
    {
    for(NODEPTR temp = p; temp->next != NULL; temp = temp->next)
    cout << temp->info << endl;
    }
    void insert_after(NODEPTR p,int x)
    {
    NODEPTR temp = p;

    while(temp->next != NULL)
    {
    temp = temp->next;
    }

    if (p==NULL){
    printf("void insertion lost");
    exit(1);
    }

    NODEPTR q = getnode();
    q->info = x;
    q->next = NULL;

    temp->next = q;
    }
    0 ...