লিংকড লিস্ট ডাইনামিক মেমরি অ্যালোকেশন ব্যবহার করে অর্থাৎ তারা আকার বড়ায় এবং ছোট করে। এটি নোডের সংগ্রহ।
নোডের দুটি অংশ থাকে:
- ডেটা
- লিংক
লিংকড লিস্টের প্রকারভেদ
সি প্রোগ্রামিং ভাষায় লিংকড লিস্টের প্রকারভেদ:
- সিঙ্গলি লিংকড লিস্ট
- ডাবলি লিংকড লিস্ট
- সার্কুলার সিঙ্গল লিংকড লিস্ট
- সার্কুলার ডাবল লিংকড লিস্ট
অ্যালগরিদম
ডাইনামিক লিংকড লিস্ট ব্যবহার করে কার ইনফরমেশন স্টোর করার অ্যালগরিদম:
Step 1 − স্ট্রাকচার ভেরিয়েবল ডিক্লেয়ার করুন।
Step 2 − ডিসপ্লে ফাংশন ডিফাইন করুন।
Step 3 − ভেরিয়েবলকে ডাইনামিক মেমরি অ্যালোকেট করুন।
Step 4 − ডু-হোয়াইল লুপ ব্যবহার করে কার ইনফরমেশন ইনপুট নিন।
Step 5 − ডিসপ্লে ফাংশন কল করুন, step 2-এ যান।
উদাহরণ
ডাইনামিক লিংকড লিস্ট ব্যবহার করে কার ইনফরমেশন স্টোর করার সি প্রোগ্রাম:
#include<stdio.h> #include<stdlib.h> #include<string.h> struct node{ char model[10],color[10]; int year; struct node *next; }; struct node *temp,*head; void display(struct node *head){ temp=head; while(temp!=NULL){ if(temp->year>2010 && (strcmp("yellow",temp->color)==0)) printf(" %s \t\t %s \t\t %d",temp->model,temp->color,temp->year); temp=temp->next; printf("\n"); } } int main(){ int n; char option,enter; head=(struct node *)malloc(sizeof(struct node)); temp=head; do{ printf("\nenter car model: "); scanf("%s",temp->model); printf("enter car color: "); scanf("%s",temp->color); printf("enter car year: "); scanf("%d",&temp->year); printf("\nDo you want continue Y(es) | N(o) : "); scanf("%c",&enter); scanf("%c",&option); if (option!='N'){ temp->next=(struct node *)malloc(sizeof(struct node)); temp=temp->next; } else { temp->next=NULL; } }while(option!='N'); display(head); return 0; }
আউটপুট
enter car model: I20 enter car color: white enter car year: 2016 Do you want continue Y(es) | N(o) : Y enter car model: verna enter car color: red enter car year: 2018 Do you want continue Y(es) | N(o) : Y enter car model: creta enter car color: Maroon enter car year: 2010 Do you want continue Y(es) | N(o) : N