লিঙ্কযুক্ত তালিকাগুলি গতিশীল মেমরি বরাদ্দ ব্যবহার করে যেমন সেগুলি সেই অনুযায়ী বৃদ্ধি পায় এবং সঙ্কুচিত হয়। এটি নোডের সংগ্রহ।
নোডের দুটি অংশ রয়েছে যা নিম্নরূপ -
- ডেটা
- লিঙ্ক
লিঙ্ক করা তালিকার প্রকারগুলি
সি প্রোগ্রামিং ল্যাঙ্গুয়েজে লিংকড লিস্টের ধরনগুলো হল-
- একক / এককভাবে লিঙ্ক করা তালিকা
- দ্বিগুণ / দ্বিগুণ লিঙ্কযুক্ত তালিকা
- বৃত্তাকার একক লিঙ্ক তালিকা
- বৃত্তাকার ডবল লিঙ্ক তালিকা
অ্যালগরিদম
গতিশীল লিঙ্কযুক্ত তালিকা ব্যবহার করে গাড়ির তথ্য সংরক্ষণের জন্য নীচে দেওয়া একটি অ্যালগরিদম পড়ুন৷
ধাপ 1 - গঠন ভেরিয়েবল ঘোষণা করুন।
ধাপ 2 - প্রদর্শনের জন্য ফাংশনের সংজ্ঞা ঘোষণা করুন।
ধাপ 3 - পরিবর্তনশীলের জন্য গতিশীল মেমরি বরাদ্দ করুন।
ধাপ 4 - গাড়ির তথ্য প্রবেশ করার জন্য ডু while লুপ ব্যবহার করুন।
ধাপ 5 - কল ডিসপ্লে ফাংশন ধাপ 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