SlideShare a Scribd company logo
1 of 2
Download to read offline
Given a linked list, write a function to determine if the list is symmetric. A list [l_1, l_2, ...., l_n]
is symmetric if l_1 = l_n, l_2 = l_n - 1, etc. Note that n must be an even number.
Solution
To do this:
struct node
{
char data;
struct node* next;
}*root, *top;
top =NULL; //head of stack
//pass root of linked list
bool ifSymmetric(node *root) {
node *tmp;
tmp = new (struct node);
temp = root; //use for first traversal
flag = 1;
//store in stack
while(temp != NULL) {
tmp->data = temp->data;
tmp->next = top;
top = tmp;
temp = temp->next;
}
//pop from stack
while(root != NULL) {
tmp = top;
if(root->data!=temp->data){
flag =0;
break;
}
top = top->next;
root = root->next;
}
free(temp);
return flag;
}

More Related Content

More from arihantelectronics

Which of the following molecules can diffuse through the membrane fa.pdf
Which of the following molecules can diffuse through the membrane fa.pdfWhich of the following molecules can diffuse through the membrane fa.pdf
Which of the following molecules can diffuse through the membrane fa.pdfarihantelectronics
 
2. A germ population has a growth curve of Aet At what value of i doe.pdf
2. A germ population has a growth curve of Aet At what value of i doe.pdf2. A germ population has a growth curve of Aet At what value of i doe.pdf
2. A germ population has a growth curve of Aet At what value of i doe.pdfarihantelectronics
 
What are transferred in costs When do they occurSolution T.pdf
What are transferred in costs When do they occurSolution    T.pdfWhat are transferred in costs When do they occurSolution    T.pdf
What are transferred in costs When do they occurSolution T.pdfarihantelectronics
 
We are conducting a test of the hypotheses H0 p=0.2 Ha p0.2 We fi.pdf
We are conducting a test of the hypotheses H0 p=0.2 Ha p0.2 We fi.pdfWe are conducting a test of the hypotheses H0 p=0.2 Ha p0.2 We fi.pdf
We are conducting a test of the hypotheses H0 p=0.2 Ha p0.2 We fi.pdfarihantelectronics
 
what is the function of CaCl2 on E coli cellsSolutionCalcium .pdf
what is the function of CaCl2 on E coli cellsSolutionCalcium .pdfwhat is the function of CaCl2 on E coli cellsSolutionCalcium .pdf
what is the function of CaCl2 on E coli cellsSolutionCalcium .pdfarihantelectronics
 
1. One of the things Alexis enjoys about her teams _______ is that.pdf
1. One of the things Alexis enjoys about her teams _______ is that.pdf1. One of the things Alexis enjoys about her teams _______ is that.pdf
1. One of the things Alexis enjoys about her teams _______ is that.pdfarihantelectronics
 
Social media marketing1.How linkedin is best used for business.pdf
Social media marketing1.How linkedin is best used for business.pdfSocial media marketing1.How linkedin is best used for business.pdf
Social media marketing1.How linkedin is best used for business.pdfarihantelectronics
 
A diploid organism has 8 pairs of homologous chromosomes. How many p.pdf
A diploid organism has 8 pairs of homologous chromosomes. How many p.pdfA diploid organism has 8 pairs of homologous chromosomes. How many p.pdf
A diploid organism has 8 pairs of homologous chromosomes. How many p.pdfarihantelectronics
 
Stamens, sepals, petals, and carpels are ________.1. Modified leav.pdf
Stamens, sepals, petals, and carpels are ________.1. Modified leav.pdfStamens, sepals, petals, and carpels are ________.1. Modified leav.pdf
Stamens, sepals, petals, and carpels are ________.1. Modified leav.pdfarihantelectronics
 
Prove that the only nonnegative superharmonic functions in R are the.pdf
Prove that the only nonnegative superharmonic functions in R are the.pdfProve that the only nonnegative superharmonic functions in R are the.pdf
Prove that the only nonnegative superharmonic functions in R are the.pdfarihantelectronics
 
Problem 5.21The increase or decrease in the price of a stock betwe.pdf
Problem 5.21The increase or decrease in the price of a stock betwe.pdfProblem 5.21The increase or decrease in the price of a stock betwe.pdf
Problem 5.21The increase or decrease in the price of a stock betwe.pdfarihantelectronics
 
Option #1 Stakeholder Influence on Project OutcomesSearch the Int.pdf
Option #1 Stakeholder Influence on Project OutcomesSearch the Int.pdfOption #1 Stakeholder Influence on Project OutcomesSearch the Int.pdf
Option #1 Stakeholder Influence on Project OutcomesSearch the Int.pdfarihantelectronics
 
Need the key terms fill in blanks answered cost records til he and I.pdf
Need the key terms fill in blanks answered cost records til he and I.pdfNeed the key terms fill in blanks answered cost records til he and I.pdf
Need the key terms fill in blanks answered cost records til he and I.pdfarihantelectronics
 
Modern portfolio theory assumes that most investors areRisk neutra.pdf
Modern portfolio theory assumes that most investors areRisk neutra.pdfModern portfolio theory assumes that most investors areRisk neutra.pdf
Modern portfolio theory assumes that most investors areRisk neutra.pdfarihantelectronics
 
1. John has tyoe o blood. His child has type A blood. What type of bl.pdf
1. John has tyoe o blood. His child has type A blood. What type of bl.pdf1. John has tyoe o blood. His child has type A blood. What type of bl.pdf
1. John has tyoe o blood. His child has type A blood. What type of bl.pdfarihantelectronics
 
definition of Intellectual Capture.SolutionIntellectual captur.pdf
definition of Intellectual Capture.SolutionIntellectual captur.pdfdefinition of Intellectual Capture.SolutionIntellectual captur.pdf
definition of Intellectual Capture.SolutionIntellectual captur.pdfarihantelectronics
 
Look at the flowering plant life cycle Which of the following is.pdf
Look at the flowering plant life cycle Which of the following is.pdfLook at the flowering plant life cycle Which of the following is.pdf
Look at the flowering plant life cycle Which of the following is.pdfarihantelectronics
 
In the right conditions, DNA structure is stable to the degree tha.pdf
In the right conditions, DNA structure is stable to the degree tha.pdfIn the right conditions, DNA structure is stable to the degree tha.pdf
In the right conditions, DNA structure is stable to the degree tha.pdfarihantelectronics
 
Know the 4 major classifications that reside in domain Eukarya.pdf
Know the 4 major classifications that reside in domain Eukarya.pdfKnow the 4 major classifications that reside in domain Eukarya.pdf
Know the 4 major classifications that reside in domain Eukarya.pdfarihantelectronics
 
Explain please. ii. Which of the measures of center is most affected.pdf
Explain please. ii. Which of the measures of center is most affected.pdfExplain please. ii. Which of the measures of center is most affected.pdf
Explain please. ii. Which of the measures of center is most affected.pdfarihantelectronics
 

More from arihantelectronics (20)

Which of the following molecules can diffuse through the membrane fa.pdf
Which of the following molecules can diffuse through the membrane fa.pdfWhich of the following molecules can diffuse through the membrane fa.pdf
Which of the following molecules can diffuse through the membrane fa.pdf
 
2. A germ population has a growth curve of Aet At what value of i doe.pdf
2. A germ population has a growth curve of Aet At what value of i doe.pdf2. A germ population has a growth curve of Aet At what value of i doe.pdf
2. A germ population has a growth curve of Aet At what value of i doe.pdf
 
What are transferred in costs When do they occurSolution T.pdf
What are transferred in costs When do they occurSolution    T.pdfWhat are transferred in costs When do they occurSolution    T.pdf
What are transferred in costs When do they occurSolution T.pdf
 
We are conducting a test of the hypotheses H0 p=0.2 Ha p0.2 We fi.pdf
We are conducting a test of the hypotheses H0 p=0.2 Ha p0.2 We fi.pdfWe are conducting a test of the hypotheses H0 p=0.2 Ha p0.2 We fi.pdf
We are conducting a test of the hypotheses H0 p=0.2 Ha p0.2 We fi.pdf
 
what is the function of CaCl2 on E coli cellsSolutionCalcium .pdf
what is the function of CaCl2 on E coli cellsSolutionCalcium .pdfwhat is the function of CaCl2 on E coli cellsSolutionCalcium .pdf
what is the function of CaCl2 on E coli cellsSolutionCalcium .pdf
 
1. One of the things Alexis enjoys about her teams _______ is that.pdf
1. One of the things Alexis enjoys about her teams _______ is that.pdf1. One of the things Alexis enjoys about her teams _______ is that.pdf
1. One of the things Alexis enjoys about her teams _______ is that.pdf
 
Social media marketing1.How linkedin is best used for business.pdf
Social media marketing1.How linkedin is best used for business.pdfSocial media marketing1.How linkedin is best used for business.pdf
Social media marketing1.How linkedin is best used for business.pdf
 
A diploid organism has 8 pairs of homologous chromosomes. How many p.pdf
A diploid organism has 8 pairs of homologous chromosomes. How many p.pdfA diploid organism has 8 pairs of homologous chromosomes. How many p.pdf
A diploid organism has 8 pairs of homologous chromosomes. How many p.pdf
 
Stamens, sepals, petals, and carpels are ________.1. Modified leav.pdf
Stamens, sepals, petals, and carpels are ________.1. Modified leav.pdfStamens, sepals, petals, and carpels are ________.1. Modified leav.pdf
Stamens, sepals, petals, and carpels are ________.1. Modified leav.pdf
 
Prove that the only nonnegative superharmonic functions in R are the.pdf
Prove that the only nonnegative superharmonic functions in R are the.pdfProve that the only nonnegative superharmonic functions in R are the.pdf
Prove that the only nonnegative superharmonic functions in R are the.pdf
 
Problem 5.21The increase or decrease in the price of a stock betwe.pdf
Problem 5.21The increase or decrease in the price of a stock betwe.pdfProblem 5.21The increase or decrease in the price of a stock betwe.pdf
Problem 5.21The increase or decrease in the price of a stock betwe.pdf
 
Option #1 Stakeholder Influence on Project OutcomesSearch the Int.pdf
Option #1 Stakeholder Influence on Project OutcomesSearch the Int.pdfOption #1 Stakeholder Influence on Project OutcomesSearch the Int.pdf
Option #1 Stakeholder Influence on Project OutcomesSearch the Int.pdf
 
Need the key terms fill in blanks answered cost records til he and I.pdf
Need the key terms fill in blanks answered cost records til he and I.pdfNeed the key terms fill in blanks answered cost records til he and I.pdf
Need the key terms fill in blanks answered cost records til he and I.pdf
 
Modern portfolio theory assumes that most investors areRisk neutra.pdf
Modern portfolio theory assumes that most investors areRisk neutra.pdfModern portfolio theory assumes that most investors areRisk neutra.pdf
Modern portfolio theory assumes that most investors areRisk neutra.pdf
 
1. John has tyoe o blood. His child has type A blood. What type of bl.pdf
1. John has tyoe o blood. His child has type A blood. What type of bl.pdf1. John has tyoe o blood. His child has type A blood. What type of bl.pdf
1. John has tyoe o blood. His child has type A blood. What type of bl.pdf
 
definition of Intellectual Capture.SolutionIntellectual captur.pdf
definition of Intellectual Capture.SolutionIntellectual captur.pdfdefinition of Intellectual Capture.SolutionIntellectual captur.pdf
definition of Intellectual Capture.SolutionIntellectual captur.pdf
 
Look at the flowering plant life cycle Which of the following is.pdf
Look at the flowering plant life cycle Which of the following is.pdfLook at the flowering plant life cycle Which of the following is.pdf
Look at the flowering plant life cycle Which of the following is.pdf
 
In the right conditions, DNA structure is stable to the degree tha.pdf
In the right conditions, DNA structure is stable to the degree tha.pdfIn the right conditions, DNA structure is stable to the degree tha.pdf
In the right conditions, DNA structure is stable to the degree tha.pdf
 
Know the 4 major classifications that reside in domain Eukarya.pdf
Know the 4 major classifications that reside in domain Eukarya.pdfKnow the 4 major classifications that reside in domain Eukarya.pdf
Know the 4 major classifications that reside in domain Eukarya.pdf
 
Explain please. ii. Which of the measures of center is most affected.pdf
Explain please. ii. Which of the measures of center is most affected.pdfExplain please. ii. Which of the measures of center is most affected.pdf
Explain please. ii. Which of the measures of center is most affected.pdf
 

Recently uploaded

e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfcupulin
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaEADTU
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMELOISARIVERA8
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 

Recently uploaded (20)

e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 

Given a linked list, write a function to determine if the list is sym.pdf

  • 1. Given a linked list, write a function to determine if the list is symmetric. A list [l_1, l_2, ...., l_n] is symmetric if l_1 = l_n, l_2 = l_n - 1, etc. Note that n must be an even number. Solution To do this: struct node { char data; struct node* next; }*root, *top; top =NULL; //head of stack //pass root of linked list bool ifSymmetric(node *root) { node *tmp; tmp = new (struct node); temp = root; //use for first traversal flag = 1; //store in stack while(temp != NULL) { tmp->data = temp->data; tmp->next = top; top = tmp; temp = temp->next; } //pop from stack while(root != NULL) { tmp = top; if(root->data!=temp->data){ flag =0; break; } top = top->next; root = root->next;