SlideShare a Scribd company logo
1 of 2
Download to read offline
write recursive function that calculates and returns the length of a linked list
Solution
// C code to determine length of linked list recursively
#include
#include
// node of linked list
struct node
{
int key;
struct node* next;
};
// push key to linked list
void push(struct node** root, int new_element)
{
struct node* nodeNew = (struct node*) malloc(sizeof(struct node));
nodeNew->key = new_element;
nodeNew->next = (*root);
(*root) = nodeNew;
}
// recursively get length of linked list
int lengthLinkedlist(struct node* root)
{
// base case
if (root == NULL)
return 0;
// recursively call the function
return 1 + lengthLinkedlist(root->next);
}
int main()
{
struct node* root = NULL;
push(&root, 11);
push(&root, 34);
push(&root, 4);
push(&root, 23);
push(&root, 14);
push(&root, 88);
push(&root, 56);
push(&root, 84);
push(&root, 6);
/* Check the count function */
printf("Length of Linked list: %d ", lengthLinkedlist(root));
return 0;
}
/*
output:
Length of Linked list: 9
*/

More Related Content

Similar to write recursive function that calculates and returns the length of a.pdf

How to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfHow to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfarihantelehyb
 
Below is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxBelow is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxgilliandunce53776
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfpoblettesedanoree498
 
#includestdio.h#includestring.h#includestdlib.h#define M.pdf
#includestdio.h#includestring.h#includestdlib.h#define M.pdf#includestdio.h#includestring.h#includestdlib.h#define M.pdf
#includestdio.h#includestring.h#includestdlib.h#define M.pdfANJALIENTERPRISES1
 
coding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docxcoding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docxtienlivick
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdfadityastores21
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfinfo114
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfamitbagga0808
 
Write java program using linked list to get integer from user and.docx
 Write java program using linked list to get integer from user and.docx Write java program using linked list to get integer from user and.docx
Write java program using linked list to get integer from user and.docxajoy21
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxteyaj1
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdffathimahardwareelect
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdffortmdu
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfrohit219406
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxBrianGHiNewmanv
 
C code on linked list #include stdio.h #include stdlib.h.pdf
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdfdeepua8
 
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfA)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfanton291
 
Program to insert in a sorted list #includestdio.h#include.pdf
 Program to insert in a sorted list #includestdio.h#include.pdf Program to insert in a sorted list #includestdio.h#include.pdf
Program to insert in a sorted list #includestdio.h#include.pdfsudhirchourasia86
 
For each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdfFor each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdfdhavalbl38
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
 

Similar to write recursive function that calculates and returns the length of a.pdf (20)

How to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfHow to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdf
 
Below is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docxBelow is a depiction of a doubly-linked list implementation of the bag.docx
Below is a depiction of a doubly-linked list implementation of the bag.docx
 
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdfC++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
 
#includestdio.h#includestring.h#includestdlib.h#define M.pdf
#includestdio.h#includestring.h#includestdlib.h#define M.pdf#includestdio.h#includestring.h#includestdlib.h#define M.pdf
#includestdio.h#includestring.h#includestdlib.h#define M.pdf
 
coding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docxcoding in C- Create a function called reverseList that takes the head.docx
coding in C- Create a function called reverseList that takes the head.docx
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdf
 
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdfNeed done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
Need done for Date Structures please! 4-18 LAB- Sorted number list imp.pdf
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdf
 
Write java program using linked list to get integer from user and.docx
 Write java program using linked list to get integer from user and.docx Write java program using linked list to get integer from user and.docx
Write java program using linked list to get integer from user and.docx
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
 
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdfTHE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdf
 
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdfAssignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
Assignment isPage 349-350 #4 and #5 Use the Linked List lab.pdf
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
 
C++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docxC++ Please write the whole code that is needed for this assignment- wr.docx
C++ Please write the whole code that is needed for this assignment- wr.docx
 
C code on linked list #include stdio.h #include stdlib.h.pdf
 C code on linked list #include stdio.h #include stdlib.h.pdf C code on linked list #include stdio.h #include stdlib.h.pdf
C code on linked list #include stdio.h #include stdlib.h.pdf
 
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdfA)B) C++ program to create a Complete Binary tree from its Lin.pdf
A)B) C++ program to create a Complete Binary tree from its Lin.pdf
 
Program to insert in a sorted list #includestdio.h#include.pdf
 Program to insert in a sorted list #includestdio.h#include.pdf Program to insert in a sorted list #includestdio.h#include.pdf
Program to insert in a sorted list #includestdio.h#include.pdf
 
For each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdfFor each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdf
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 

More from arpitcomputronics

Neutrons cant be detected by the same detectors as alphas, betas, and.pdf
Neutrons cant be detected by the same detectors as alphas, betas, and.pdfNeutrons cant be detected by the same detectors as alphas, betas, and.pdf
Neutrons cant be detected by the same detectors as alphas, betas, and.pdfarpitcomputronics
 
List each hypothesis that is being tested in a twofactor ANOVA.S.pdf
List each hypothesis that is being tested in a twofactor ANOVA.S.pdfList each hypothesis that is being tested in a twofactor ANOVA.S.pdf
List each hypothesis that is being tested in a twofactor ANOVA.S.pdfarpitcomputronics
 
Marla begins walking at 3 mih toward the library.Her friend meets h.pdf
Marla begins walking at 3 mih toward the library.Her friend meets h.pdfMarla begins walking at 3 mih toward the library.Her friend meets h.pdf
Marla begins walking at 3 mih toward the library.Her friend meets h.pdfarpitcomputronics
 
Mrs. S confides in you that she is terrified of her husband. She rep.pdf
Mrs. S confides in you that she is terrified of her husband. She rep.pdfMrs. S confides in you that she is terrified of her husband. She rep.pdf
Mrs. S confides in you that she is terrified of her husband. She rep.pdfarpitcomputronics
 
In September of 2008, the FDIC paid JP Morgan Chase to purchase all .pdf
In September of 2008, the FDIC paid JP Morgan Chase to purchase all .pdfIn September of 2008, the FDIC paid JP Morgan Chase to purchase all .pdf
In September of 2008, the FDIC paid JP Morgan Chase to purchase all .pdfarpitcomputronics
 
In cocker spaniels, black coat color (B) is dominant over red (b), an.pdf
In cocker spaniels, black coat color (B) is dominant over red (b), an.pdfIn cocker spaniels, black coat color (B) is dominant over red (b), an.pdf
In cocker spaniels, black coat color (B) is dominant over red (b), an.pdfarpitcomputronics
 
In most healthy people, toxoplasmosis is an inapparent or mild dise.pdf
In most healthy people, toxoplasmosis is an inapparent or mild dise.pdfIn most healthy people, toxoplasmosis is an inapparent or mild dise.pdf
In most healthy people, toxoplasmosis is an inapparent or mild dise.pdfarpitcomputronics
 
I only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdfI only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdfarpitcomputronics
 
Identify and briefly describe a diffusion network that you have expe.pdf
Identify and briefly describe a diffusion network that you have expe.pdfIdentify and briefly describe a diffusion network that you have expe.pdf
Identify and briefly describe a diffusion network that you have expe.pdfarpitcomputronics
 
how do the masses of the earth, oceans, atmosphere, and biosphere co.pdf
how do the masses of the earth, oceans, atmosphere, and biosphere co.pdfhow do the masses of the earth, oceans, atmosphere, and biosphere co.pdf
how do the masses of the earth, oceans, atmosphere, and biosphere co.pdfarpitcomputronics
 
If the mechanism of DNA replication (semi-conservative, conservative.pdf
If the mechanism of DNA replication (semi-conservative, conservative.pdfIf the mechanism of DNA replication (semi-conservative, conservative.pdf
If the mechanism of DNA replication (semi-conservative, conservative.pdfarpitcomputronics
 
EYCONNEC Cell Structures the arrangement of phospholipids in the plas.pdf
EYCONNEC Cell Structures the arrangement of phospholipids in the plas.pdfEYCONNEC Cell Structures the arrangement of phospholipids in the plas.pdf
EYCONNEC Cell Structures the arrangement of phospholipids in the plas.pdfarpitcomputronics
 
For the balance sheet, please categorize the following as short-term.pdf
For the balance sheet, please categorize the following as short-term.pdfFor the balance sheet, please categorize the following as short-term.pdf
For the balance sheet, please categorize the following as short-term.pdfarpitcomputronics
 
During World War II, the Manhattan Project developed the first nuclea.pdf
During World War II, the Manhattan Project developed the first nuclea.pdfDuring World War II, the Manhattan Project developed the first nuclea.pdf
During World War II, the Manhattan Project developed the first nuclea.pdfarpitcomputronics
 
Deoxy sugars are modified sugars where one or more OH groups are remo.pdf
Deoxy sugars are modified sugars where one or more OH groups are remo.pdfDeoxy sugars are modified sugars where one or more OH groups are remo.pdf
Deoxy sugars are modified sugars where one or more OH groups are remo.pdfarpitcomputronics
 
Determine truth value of the statement. Domain consists of all real .pdf
Determine truth value of the statement. Domain consists of all real .pdfDetermine truth value of the statement. Domain consists of all real .pdf
Determine truth value of the statement. Domain consists of all real .pdfarpitcomputronics
 
Describe the niches of at least 3 species of wildlife that might be .pdf
Describe the niches of at least 3 species of wildlife that might be .pdfDescribe the niches of at least 3 species of wildlife that might be .pdf
Describe the niches of at least 3 species of wildlife that might be .pdfarpitcomputronics
 
Define multicollinearity in the following termsa. In which type o.pdf
Define multicollinearity in the following termsa. In which type o.pdfDefine multicollinearity in the following termsa. In which type o.pdf
Define multicollinearity in the following termsa. In which type o.pdfarpitcomputronics
 
Convert the for loop Into MIPS Instructions. Use the sit instruction .pdf
Convert the for loop Into MIPS Instructions. Use the sit instruction .pdfConvert the for loop Into MIPS Instructions. Use the sit instruction .pdf
Convert the for loop Into MIPS Instructions. Use the sit instruction .pdfarpitcomputronics
 
Clarify how cells and molecules are linked to tissuesSolutionA.pdf
Clarify how cells and molecules are linked to tissuesSolutionA.pdfClarify how cells and molecules are linked to tissuesSolutionA.pdf
Clarify how cells and molecules are linked to tissuesSolutionA.pdfarpitcomputronics
 

More from arpitcomputronics (20)

Neutrons cant be detected by the same detectors as alphas, betas, and.pdf
Neutrons cant be detected by the same detectors as alphas, betas, and.pdfNeutrons cant be detected by the same detectors as alphas, betas, and.pdf
Neutrons cant be detected by the same detectors as alphas, betas, and.pdf
 
List each hypothesis that is being tested in a twofactor ANOVA.S.pdf
List each hypothesis that is being tested in a twofactor ANOVA.S.pdfList each hypothesis that is being tested in a twofactor ANOVA.S.pdf
List each hypothesis that is being tested in a twofactor ANOVA.S.pdf
 
Marla begins walking at 3 mih toward the library.Her friend meets h.pdf
Marla begins walking at 3 mih toward the library.Her friend meets h.pdfMarla begins walking at 3 mih toward the library.Her friend meets h.pdf
Marla begins walking at 3 mih toward the library.Her friend meets h.pdf
 
Mrs. S confides in you that she is terrified of her husband. She rep.pdf
Mrs. S confides in you that she is terrified of her husband. She rep.pdfMrs. S confides in you that she is terrified of her husband. She rep.pdf
Mrs. S confides in you that she is terrified of her husband. She rep.pdf
 
In September of 2008, the FDIC paid JP Morgan Chase to purchase all .pdf
In September of 2008, the FDIC paid JP Morgan Chase to purchase all .pdfIn September of 2008, the FDIC paid JP Morgan Chase to purchase all .pdf
In September of 2008, the FDIC paid JP Morgan Chase to purchase all .pdf
 
In cocker spaniels, black coat color (B) is dominant over red (b), an.pdf
In cocker spaniels, black coat color (B) is dominant over red (b), an.pdfIn cocker spaniels, black coat color (B) is dominant over red (b), an.pdf
In cocker spaniels, black coat color (B) is dominant over red (b), an.pdf
 
In most healthy people, toxoplasmosis is an inapparent or mild dise.pdf
In most healthy people, toxoplasmosis is an inapparent or mild dise.pdfIn most healthy people, toxoplasmosis is an inapparent or mild dise.pdf
In most healthy people, toxoplasmosis is an inapparent or mild dise.pdf
 
I only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdfI only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdf
 
Identify and briefly describe a diffusion network that you have expe.pdf
Identify and briefly describe a diffusion network that you have expe.pdfIdentify and briefly describe a diffusion network that you have expe.pdf
Identify and briefly describe a diffusion network that you have expe.pdf
 
how do the masses of the earth, oceans, atmosphere, and biosphere co.pdf
how do the masses of the earth, oceans, atmosphere, and biosphere co.pdfhow do the masses of the earth, oceans, atmosphere, and biosphere co.pdf
how do the masses of the earth, oceans, atmosphere, and biosphere co.pdf
 
If the mechanism of DNA replication (semi-conservative, conservative.pdf
If the mechanism of DNA replication (semi-conservative, conservative.pdfIf the mechanism of DNA replication (semi-conservative, conservative.pdf
If the mechanism of DNA replication (semi-conservative, conservative.pdf
 
EYCONNEC Cell Structures the arrangement of phospholipids in the plas.pdf
EYCONNEC Cell Structures the arrangement of phospholipids in the plas.pdfEYCONNEC Cell Structures the arrangement of phospholipids in the plas.pdf
EYCONNEC Cell Structures the arrangement of phospholipids in the plas.pdf
 
For the balance sheet, please categorize the following as short-term.pdf
For the balance sheet, please categorize the following as short-term.pdfFor the balance sheet, please categorize the following as short-term.pdf
For the balance sheet, please categorize the following as short-term.pdf
 
During World War II, the Manhattan Project developed the first nuclea.pdf
During World War II, the Manhattan Project developed the first nuclea.pdfDuring World War II, the Manhattan Project developed the first nuclea.pdf
During World War II, the Manhattan Project developed the first nuclea.pdf
 
Deoxy sugars are modified sugars where one or more OH groups are remo.pdf
Deoxy sugars are modified sugars where one or more OH groups are remo.pdfDeoxy sugars are modified sugars where one or more OH groups are remo.pdf
Deoxy sugars are modified sugars where one or more OH groups are remo.pdf
 
Determine truth value of the statement. Domain consists of all real .pdf
Determine truth value of the statement. Domain consists of all real .pdfDetermine truth value of the statement. Domain consists of all real .pdf
Determine truth value of the statement. Domain consists of all real .pdf
 
Describe the niches of at least 3 species of wildlife that might be .pdf
Describe the niches of at least 3 species of wildlife that might be .pdfDescribe the niches of at least 3 species of wildlife that might be .pdf
Describe the niches of at least 3 species of wildlife that might be .pdf
 
Define multicollinearity in the following termsa. In which type o.pdf
Define multicollinearity in the following termsa. In which type o.pdfDefine multicollinearity in the following termsa. In which type o.pdf
Define multicollinearity in the following termsa. In which type o.pdf
 
Convert the for loop Into MIPS Instructions. Use the sit instruction .pdf
Convert the for loop Into MIPS Instructions. Use the sit instruction .pdfConvert the for loop Into MIPS Instructions. Use the sit instruction .pdf
Convert the for loop Into MIPS Instructions. Use the sit instruction .pdf
 
Clarify how cells and molecules are linked to tissuesSolutionA.pdf
Clarify how cells and molecules are linked to tissuesSolutionA.pdfClarify how cells and molecules are linked to tissuesSolutionA.pdf
Clarify how cells and molecules are linked to tissuesSolutionA.pdf
 

Recently uploaded

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 

Recently uploaded (20)

Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 

write recursive function that calculates and returns the length of a.pdf

  • 1. write recursive function that calculates and returns the length of a linked list Solution // C code to determine length of linked list recursively #include #include // node of linked list struct node { int key; struct node* next; }; // push key to linked list void push(struct node** root, int new_element) { struct node* nodeNew = (struct node*) malloc(sizeof(struct node)); nodeNew->key = new_element; nodeNew->next = (*root); (*root) = nodeNew; } // recursively get length of linked list int lengthLinkedlist(struct node* root) { // base case if (root == NULL) return 0; // recursively call the function return 1 + lengthLinkedlist(root->next); } int main()
  • 2. { struct node* root = NULL; push(&root, 11); push(&root, 34); push(&root, 4); push(&root, 23); push(&root, 14); push(&root, 88); push(&root, 56); push(&root, 84); push(&root, 6); /* Check the count function */ printf("Length of Linked list: %d ", lengthLinkedlist(root)); return 0; } /* output: Length of Linked list: 9 */