JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi sociology physics physical education maths english economics geography History

chemistry business studies biology accountancy political science

Class 12

Hindi physics physical education maths english economics

chemistry business studies biology accountancy Political science History sociology

Home science Geography

English medium Notes

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Class 12

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

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

four potential in hindi 4-potential electrodynamics चतुर्विम विभव किसे कहते हैं

चतुर्विम विभव (Four-Potential) हम जानते हैं कि एक निर्देश तंत्र में विद्युत क्षेत्र इसके सापेक्ष…

2 days ago

Relativistic Electrodynamics in hindi आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा

आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा Relativistic Electrodynamics in hindi ? अध्याय : आपेक्षिकीय विद्युतगतिकी…

4 days ago

pair production in hindi formula definition युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए

युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए pair production in hindi formula…

6 days ago

THRESHOLD REACTION ENERGY in hindi देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा

देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा THRESHOLD REACTION ENERGY in hindi…

6 days ago

elastic collision of two particles in hindi definition formula दो कणों की अप्रत्यास्थ टक्कर क्या है

दो कणों की अप्रत्यास्थ टक्कर क्या है elastic collision of two particles in hindi definition…

6 days 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