JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: C Language in hindi

Linked List : Counting in c language in hindi , लिंक लिस्ट में काउंटिंग क्या होता है c कंप्यूटर भाषा में हिंदी में

लिंक लिस्ट में काउंटिंग क्या होता है c कंप्यूटर भाषा में हिंदी में , Linked List : Counting in c language in hindi :-
linked list मे counting , inserting और deleting operation के बाद महतवपूर्ण operation है |

counting

किसी linked लिस्ट के मे उपस्थित node की सख्या को calculate करना counting operation कहलाता  है |counting operation मे , linked list के first node से last node तक pointer traverse करता है उसके साथ ही हर एक node के लिए count की count मे increment होता है |इसकी algorithm है :
1.pointer varibale ‘a’ को linked लिस्ट के head से initial करना |
2.for count को ‘1’ से initail करना |
3.उसके बाद pointer variable ‘a’ के address को head से next node पर traverse करना और count की value मे फिर से increment होना |
4.step 3 का tab तक run होना जब तक की ‘a’ की value null नहीं हो जाती है |
5.count की value को return करना |

source code 
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
/* Structure of a node */
struct employee {
int salary;          // salary
struct employee *address; // Address
}*h;

void create_list(int n);
int count_nodes();
void display_list();

int main()
{
int num, sum ;
printf(“Enter nodes number: “);
scanf(“%d”, &num);
create_list(num);
printf(“\n salary in the list \n”);
display_list();
sum  = countNodes();
printf(“\nTotal number of nodes = %d\n”, sum );
getch();
}

void create_list(int n)
{
struct employee *addnode, *t;
int s, i;
h = (struct employee *)malloc(sizeof(struct employee));
if(h == NULL)
{
printf(“no more space “);
}
else
{
printf(“Enter the salary : “);
scanf(“%d”, &s);
h->salary = s;      // assign the user inpur salary into salary field of ‘h’
h->address = NULL; //  assign null to address field of ‘h’
t = h;
for(i=2; i<=n; i++)
{
addnode = (struct employee *)malloc(sizeof(struct employee));
if(addnode == NULL)
{
printf(” No more space “);
break;
}
else
{
printf(“Enter the salary : “);
scanf(“%d”, &s);
addnode->salary = s;     // assign the user input salary into salary field of new node
addnode->address = NULL; // assign null to address field of new node
t->address = addnode;   // node linking mean make a link between t or addnode
t = t->address;
}
}
}
}
int count_nodes()
{
int c = 0;
struct employee *temp;
temp = head;
while(temp != NULL)
{
c++;
temp = temp->address;
}
return (count);
}

void display_list()
{
struct employee *t;
if(h == NULL)
{
printf(“List is already empty .”);
}
else
{
t = h;
while(t != NULL)
{
printf(“salary = %d\n”, t->salary);
t = t->address;
}
}
}

Explanation
इस code मे , employee एक struture है जो की  linked लिस्ट के एक node को define करता है |
इसमें तीन function है :-
void create_list(int n): ये function का use , linked लिस्ट को create करने के लिए किया जाता है |
int count_nodes(): इस function का use, linked list के node को count करने के लिए किया जाता है |
void display_list(): इस function का use linked लिस्ट के सभी items को display करने के लिए किया जाता है |
main() मे ,
1.main() function मे , दो variable declare किये गये है |(i)num: ये variable linked list मे nodes की सख्या को contain करता है |(ii) sum:ये varibale मे ,count_list() से return value को contain करता है |
2.यूजर से node की सख्या को input कराया  जाता है |फिर create_list function मे pass किया जाता है |
3.फिर display_list function से linked लिस्ट के सभी items को display किया जाता है |
4. count_list() function से मिला आउटपुट को variable ‘sum’ मे received किया जाता है |
5.printf() statement से number of nodes को print करा दिया जाता है |

void create_list(int n) मे ,
1.सबसे पहले दो pointer variable addnode, t को declare किया जाता है जी की struture data  है
2.इसके अलावा दो variable ‘s’ और ‘i’ को declare किया गया है |
3.फिर pointer variable ‘h’ मे dynamic memory allocate space के address को store किया जाता है |
अगर pointer की null होती तो no more space का meassage आउटपुट होगा |
अन्यथा  ‘h’ के item feild मे user input salary को assign किया जाता है |और ‘h’ के address field को ‘null’ assign किया जाता है |इस प्रकार से linked list create हो जाती है लेकिन इसमें केवल एक ही node है |
4.create linked लिस्ट मे , यूजर द्वारा दिए node को insert करने के लिए for loop चलाया जाता है |जिसमे addnode pointer मे , allocate memory के address को assign करा देते है |
अगर addnode की value null होती तब no more space का message print हो जाता है |
अन्यथा
addnode के item field मे , यूजर input salary को assign किया जाता है और addnode के address field को null से assign किया जाता  है |
linking की जाती है इसका मतलब है ‘t’ variable के address field मे addnode के address को assign किया जाता है |और t को t address बनाया जाता है |

void display_list() मे ,
1.सबसे पहले एक variable को declare किया जाता है जिसका data type structure employee है |
2.अगर head pointer ‘h’ null है tab empty लिस्ट का message आएगा |
अन्यथा t की h से initial करेगे |फिर while loop चलायेगे |
3.while loop की body मे , printf() statement से head pointer या  ‘t’ की item को display करा देगे |
फिर t को t के address field मे सेव address से set करगे |
4.step 3 जब तक्क चलगे जब तक की t का address feild मे null नहीं आ जाता है |

int count_nodes() मे 
1.सबसे पहले एक variable ‘temp’ को declare किया जाता है जिसका data type structure employee है |
2.अगर head pointer ‘h’ null है तब empty लिस्ट का message आएगा |
अन्यथा temp की h से initial करेगे |फिर while loop चलायेगे |
3.while loop की body मे , count को 1 से set करगे और temp को temp  के address field मे सेव address से set करेगे |
4. while loop मे , temp की address field को check करेगे |अगर null नहीं है तब , count को 2 से set करगे और temp को temp के address से set करेगे |
5.step 3 और step 4  तक चलता रहेगा जब तक की temp  की address field की value null नहीं हो जाती है |
6.count की value को return करेगे |
इस code का आउटपुट होगा :
Enter nodes number: 4
Enter the salary : 1200
Enter the salary : 2000
Enter the salary : 3000
Enter the salary : 4000
salary in the list
salary = 1200
salary = 2000
salary = 3000
salary = 4000
Total number of nodes = 4

Sbistudy

Recent Posts

सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है

सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…

1 day ago

मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the

marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…

1 day ago

राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi

sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…

3 days ago

गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi

gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…

3 days ago

Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन

वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…

3 months ago

polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten

get all types and chapters polity notes pdf in hindi for upsc , SSC ,…

3 months ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now