SlideShare a Scribd company logo
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.pdf
arihantelehyb
 
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
gilliandunce53776
 
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
poblettesedanoree498
 
#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
ANJALIENTERPRISES1
 
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
tienlivick
 
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
adityastores21
 
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
info114
 
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
amitbagga0808
 
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
ajoy21
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
teyaj1
 
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
fathimahardwareelect
 
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
fortmdu
 
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
rohit219406
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
DaniyalAli81
 
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
BrianGHiNewmanv
 
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
deepua8
 
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
anton291
 
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
sudhirchourasia86
 
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
dhavalbl38
 
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
EricvtJFraserr
 

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.pdf
arpitcomputronics
 
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
arpitcomputronics
 
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
arpitcomputronics
 
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
arpitcomputronics
 
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
arpitcomputronics
 
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
arpitcomputronics
 
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
arpitcomputronics
 
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
arpitcomputronics
 
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
arpitcomputronics
 
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
arpitcomputronics
 
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
arpitcomputronics
 
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
arpitcomputronics
 
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
arpitcomputronics
 
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
arpitcomputronics
 
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
arpitcomputronics
 
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
arpitcomputronics
 
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
arpitcomputronics
 
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
arpitcomputronics
 
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
arpitcomputronics
 
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
arpitcomputronics
 

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

Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 

Recently uploaded (20)

Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 

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 */