Linked List : Creating Operation in c language in hindi , लिंक लिस्ट में लिस्ट बनाने का ऑपरेशन हिंदी में

लिंक लिस्ट में लिस्ट बनाने का ऑपरेशन हिंदी में Linked List : Creating Operation in c language in hindi :-
जब हम किसी linked लिस्ट को data type की तरह काम करते है तब इसमें निम्न operation perform हो सकते है :-
1. Creating a list
2. Traversing a list
3. counting the item in the list
4. printing a list
5. Inserting an item
6. Deleting an item
Creating a list / Traversing a list
इससे पहले के article मे हमने एक linked लिस्ट बनाई थी जिसमे दो item store हो सकते है |किसी लिस्ट मे pointer variable को create करने के लिए ‘&’ और pointer variable के value को access करने के लिए ‘*’ use किया जाता है |उदाहरण के लिए node एक structure variable है जिसमे से element ‘salary’ को access करने के लिए node->salary या node.salary को use कर सकते है |
linked list को dynamic बनाने के लिए malloc function का use किया जाता है |उदाहरन के लिए :
struct employee
{
char name[20];
int salary ;
struct employee *emp;
};
struct employee em;
em *head;
head=(em *) malloc(sizeof(em));
यहाँ पर :
struct employee : यहा पर structure linked list के एक node को define करता है जिसमे दो item है(i)string name (ii) salary
struct employee em : इस statement से एक structure type का variable होता है |
उसके बाद
em *head : एक pointer variable declare होता है जोकि malloc function से allocate space से जो return value को contain करेगा|
उसके बाद malloc statement से एक dynamic memory एलोकेशन हो जाता है |
उदाहरण के लिए
#include <stdio.h>
#include <stdlib.h>
struct node
{
int salary;                        //Data of the node
struct node *address;      //Address of the next node
}*node ;
void create_list(int n);     // function to create the list
void display_list();         // function to display the list
int main()
{
int num;
printf(“\n\n Linked List Creation \n”);
printf(” Input the number of nodes : “);
scanf(“%d”, &num);
create_list(num);
printf(“\n Linked List Display Start \n”);
display_list();
getch();
}
void create_list(int n)
{
struct node *first_node, *temp,*head;
int salary, i,n;
head  = (struct node *)malloc(sizeof(struct node));
if(head  == NULL)
{
printf(” No more space “);
}
else
{
/* user input */
printf(” Input salary  : “);
scanf(“%d”, &salary);
head  ->salary = salary;
head ->address = NULL;
temp = head ;
/* Creating n nodes and adding to linked list */
for(i=2; i<=n; i++)
{
first_node = (struct node *)malloc(sizeof(struct node));
if(first_node == NULL)
{
printf(” No more space”);
break;
}
else
{
printf(” Input salary : “);
scanf(” %d”, &salary);
first_node->salary = salary;
first_node->address = NULL;
temp->address = first_node;
temp = temp->address;
}
}
}
}
void display_list()
{
struct node *temp;
if(head  == NULL)
{
printf(” List is empty.”);
}
else
{
temp = head ;
while(temp != NULL)
{
printf(” Salary = %d\n”, temp->salary);
temp = temp->address;
}
}
}
Explanation
इस उदाहरण मे ,
किसी linked लिस्ट के node को declare किया गया है जिसमे salary data item है और address एक pointer variable है जिसमे की next node का address store होता है |
इसके बाद दो function को declare किया है :-
void create_list(int n) : इस function से linked लिस्ट को create किया जाता है |
void display_list(): इस function से linked list को display किया जाता है |
main() मे ,
इस function मे ,यूजर से salary को input लेते है जिसे variable साल मे assign करते और void creat_list() मे pass किया जाता है |
बाद मे void display_list() को call किया जाता है
void create_list(int n) मे ,
सबसे पहले ,एक memory block को allocate करते है जिसका address pointer variable ‘head’ मे store किया है |
अगर pointer variable ‘head’ मे null value होगी , तब no more space का message आएगा |
अगर null नहीं है तो head के salary item मे यूजर द्वारा input value को assign होता है और head का pointer variable address मे null value store हो जाती है |और structure type variable temp मे head भी store हो जाता है |
उसके बाद मे linked list के बाकि के node को बनायेगे और उसे linked list मे add करेगे |
इस operation के loop चलेगा |
फिर dynamic memory allocate होगी और इसके address को first_node मे store करा देते है |उसके बाद first node के item मे data को add करेगे |और इसके pointer variable मे null value assign हो जाती है |
इसके बाद temp variable के pointer variable मे first node का address store हो जायेगा |
Display_list()
इस function मे linked list के सभी element को display करेगे |इसमें
1.सबसे पहले structure type node का एक pointer ‘temp’ को करता है |
2.उसके बाद head की value  check होती |अगर head की value null है तब empty linked लिस्ट message आएगा |
3. उसके बाद declare variable temp मे head को assign करा देते है |
4.अगर null value नहीं होती तब while loop मे temp != NULL की condition के साथ चलेगा |
उसके बाद temp के salary item मे store value को print हो जायेगे |
फिर temp का address अगले वाले node का address contain करता है |फिर से loop चलता है |
ये loop तब तक चलता है जब तक temp का address null नहीं हो जाता है |
आउटपुट होगा :
Linked List Creation
Input the number of nodes : 3
Input salary  : 2000
Input salary  : 3000
Input salary  : 4000
Linked List Display Start
Salary= 2000
Salary= 3000
Salary= 4000