SlideShare a Scribd company logo
reverse the linked list (2,4,8,10) by:
stack;
iteration;
recursion.
Using C++
Solution
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#includ<stack>
using namespace std;
struct Node {
int value;
struct Node* next;
}node;
struct Node* reverse(struct Node* head) {Â Â // Iteration Method
struct Node* current,*prev;
current = head;
prev = NULL;
while(current!=NULL) {
next = current->next;
current->next = prev;
prev = current;
current = next; }
head = prev;-
return head; }
struct Node* insert(Node* head,int value) {
Node* temp = (struct Node*)malloc(sizeof(struct Node));
temp->value = value;
temp->next = NULL;
if(head = = NULL)
head = temp;
else {
Node*temp1=head;
while(temp1->next!=NULL)
temp1 = temp1->next;
temp1->next = temp;
} return head;
}
public void print(Node* head) {
while(head!=NULL) {
cout<<head->value;
head = head->next; }
}
struct Node*recursiveReverse(struct Node* &head) {Â Â //Recursion method
if(head==NULL || head->next ==NULL) return;
Node*first = head;
Node *rest = head->next;
if(rest !=NULL) return;
recursiveReverse(rest);
first ->next->next = first;
first->next =NULL;
head = rest;
return head; }
void Reverse(struct Node* head)Â Â // stack Implementation
{
stack<node*> Stack;
node *traverse = head;
while(traverse!=NULL) {
Stack.push(traverse);
traverse = traverse->next;Â Â }
node *temp = Stack.top();
head = temp;
Stack.pop();
while(!Stack.empty()) {
temp->next = Stack.top();
Stack.pop();
temp = temp->next;Â Â }
temp->next = NULL;
return Stack; }
int main() {
struct Node* head =NULL;
head = insert(head,2);
head = insert(head,4);
head = insert(head,8);
head = insert(head,10);
print(head);
head= reverse(head);
print(head);
head = recursiveReverse(head);
print(head);
head = void Reverse(head);
void print(head);
return 0;
}
reverse the linked list (2-4-8-10) by- stack- iteration- recursion-  U.docx

More Related Content

Similar to reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx

Binary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structureBinary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structure
ZarghamullahShah
 
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptxData Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
RashidFaridChishti
 
Help explain the code with line comments public class CompletedLis.pdf
Help explain the code with line comments public class CompletedLis.pdfHelp explain the code with line comments public class CompletedLis.pdf
Help explain the code with line comments public class CompletedLis.pdf
almonardfans
 
Solution#includestdio.h#includeconio.h#includealloc.h.pdf
Solution#includestdio.h#includeconio.h#includealloc.h.pdfSolution#includestdio.h#includeconio.h#includealloc.h.pdf
Solution#includestdio.h#includeconio.h#includealloc.h.pdf
poddaranand1
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
DaniyalAli81
 
data structure3.pptx
data structure3.pptxdata structure3.pptx
data structure3.pptx
SajalFayyaz
 
Linked lists
Linked listsLinked lists
I need to implment a function that can reverse a single linked list..pdf
I need to implment a function that can reverse a single linked list..pdfI need to implment a function that can reverse a single linked list..pdf
I need to implment a function that can reverse a single linked list..pdf
rohit219406
 
Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03Nasir Mehmood
 
Hi,you covered mostly things.there are issue to point and link poi.pdf
Hi,you covered mostly things.there are issue to point and link poi.pdfHi,you covered mostly things.there are issue to point and link poi.pdf
Hi,you covered mostly things.there are issue to point and link poi.pdf
aryan9007
 
C++Write a function void headEnqueue(Queue q, int key) which enqu.pdf
C++Write a function void headEnqueue(Queue q, int key) which enqu.pdfC++Write a function void headEnqueue(Queue q, int key) which enqu.pdf
C++Write a function void headEnqueue(Queue q, int key) which enqu.pdf
arjuncp10
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdf
mail931892
 
Linked Stack program.docx
Linked Stack program.docxLinked Stack program.docx
Linked Stack program.docx
kudikalakalabharathi
 
operating system linux,ubuntu,Mac#include iostream #include .pdf
operating system linux,ubuntu,Mac#include iostream #include .pdfoperating system linux,ubuntu,Mac#include iostream #include .pdf
operating system linux,ubuntu,Mac#include iostream #include .pdf
aquacareser
 
Please find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdfPlease find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdf
angelfragranc
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx
ajoy21
 
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docx
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docxWrite a C++ function that delete nodes in a doubly linkedlist- It shou.docx
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docx
noreendchesterton753
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
forladies
 

Similar to reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx (20)

Binary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structureBinary Tree in C++ coding in the data structure
Binary Tree in C++ coding in the data structure
 
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptxData Structures and Agorithm: DS 05 Doubly Linked List.pptx
Data Structures and Agorithm: DS 05 Doubly Linked List.pptx
 
Help explain the code with line comments public class CompletedLis.pdf
Help explain the code with line comments public class CompletedLis.pdfHelp explain the code with line comments public class CompletedLis.pdf
Help explain the code with line comments public class CompletedLis.pdf
 
Solution#includestdio.h#includeconio.h#includealloc.h.pdf
Solution#includestdio.h#includeconio.h#includealloc.h.pdfSolution#includestdio.h#includeconio.h#includealloc.h.pdf
Solution#includestdio.h#includeconio.h#includealloc.h.pdf
 
DSA(1).pptx
DSA(1).pptxDSA(1).pptx
DSA(1).pptx
 
Ds 2 cycle
Ds 2 cycleDs 2 cycle
Ds 2 cycle
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 
data structure3.pptx
data structure3.pptxdata structure3.pptx
data structure3.pptx
 
Linked lists
Linked listsLinked lists
Linked lists
 
I need to implment a function that can reverse a single linked list..pdf
I need to implment a function that can reverse a single linked list..pdfI need to implment a function that can reverse a single linked list..pdf
I need to implment a function that can reverse a single linked list..pdf
 
Data structures cs301 power point slides lecture 03
Data structures   cs301 power point slides lecture 03Data structures   cs301 power point slides lecture 03
Data structures cs301 power point slides lecture 03
 
Hi,you covered mostly things.there are issue to point and link poi.pdf
Hi,you covered mostly things.there are issue to point and link poi.pdfHi,you covered mostly things.there are issue to point and link poi.pdf
Hi,you covered mostly things.there are issue to point and link poi.pdf
 
C++Write a function void headEnqueue(Queue q, int key) which enqu.pdf
C++Write a function void headEnqueue(Queue q, int key) which enqu.pdfC++Write a function void headEnqueue(Queue q, int key) which enqu.pdf
C++Write a function void headEnqueue(Queue q, int key) which enqu.pdf
 
Help I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdfHelp I keep getting the same error when running a code. Below is the.pdf
Help I keep getting the same error when running a code. Below is the.pdf
 
Linked Stack program.docx
Linked Stack program.docxLinked Stack program.docx
Linked Stack program.docx
 
operating system linux,ubuntu,Mac#include iostream #include .pdf
operating system linux,ubuntu,Mac#include iostream #include .pdfoperating system linux,ubuntu,Mac#include iostream #include .pdf
operating system linux,ubuntu,Mac#include iostream #include .pdf
 
Please find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdfPlease find the answer to the above problem as follows- Program.pdf
Please find the answer to the above problem as follows- Program.pdf
 
#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx#include iostream#include d_node.h #include d_nodel.h.docx
#include iostream#include d_node.h #include d_nodel.h.docx
 
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docx
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docxWrite a C++ function that delete nodes in a doubly linkedlist- It shou.docx
Write a C++ function that delete nodes in a doubly linkedlist- It shou.docx
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
 

More from acarolyn

Research the issues that you might face as a network administrator whe.docx
Research the issues that you might face as a network administrator whe.docxResearch the issues that you might face as a network administrator whe.docx
Research the issues that you might face as a network administrator whe.docx
acarolyn
 
Reset Help By the Brnsted-Lowry definition- acids are proton donors an.docx
Reset Help By the Brnsted-Lowry definition- acids are proton donors an.docxReset Help By the Brnsted-Lowry definition- acids are proton donors an.docx
Reset Help By the Brnsted-Lowry definition- acids are proton donors an.docx
acarolyn
 
SECTION III- SHORT ANSWER (10 possible points) Please give a brief ans.docx
SECTION III- SHORT ANSWER (10 possible points) Please give a brief ans.docxSECTION III- SHORT ANSWER (10 possible points) Please give a brief ans.docx
SECTION III- SHORT ANSWER (10 possible points) Please give a brief ans.docx
acarolyn
 
Select a specific event that has recently occurred (within the last 30.docx
Select a specific event that has recently occurred (within the last 30.docxSelect a specific event that has recently occurred (within the last 30.docx
Select a specific event that has recently occurred (within the last 30.docx
acarolyn
 
Security Breaches and the Six Dumb Ideas Consider a recent (2014- 2015.docx
Security Breaches and the Six Dumb Ideas Consider a recent (2014- 2015.docxSecurity Breaches and the Six Dumb Ideas Consider a recent (2014- 2015.docx
Security Breaches and the Six Dumb Ideas Consider a recent (2014- 2015.docx
acarolyn
 
Scientifically continuous phase apersed phase Speaking Chapter Review.docx
Scientifically continuous phase apersed phase Speaking Chapter Review.docxScientifically continuous phase apersed phase Speaking Chapter Review.docx
Scientifically continuous phase apersed phase Speaking Chapter Review.docx
acarolyn
 
Scenario- You are the Accountant for WanneBee Corporation WannaBee Cor.docx
Scenario- You are the Accountant for WanneBee Corporation WannaBee Cor.docxScenario- You are the Accountant for WanneBee Corporation WannaBee Cor.docx
Scenario- You are the Accountant for WanneBee Corporation WannaBee Cor.docx
acarolyn
 
Scenario Allen Manesfield- Jenny Winters- and John Jacobsen have been.docx
Scenario Allen Manesfield- Jenny Winters- and John Jacobsen have been.docxScenario Allen Manesfield- Jenny Winters- and John Jacobsen have been.docx
Scenario Allen Manesfield- Jenny Winters- and John Jacobsen have been.docx
acarolyn
 
S10-2 (Learning Objective 1- Describe the authority structure in a cor.docx
S10-2 (Learning Objective 1- Describe the authority structure in a cor.docxS10-2 (Learning Objective 1- Describe the authority structure in a cor.docx
S10-2 (Learning Objective 1- Describe the authority structure in a cor.docx
acarolyn
 
rovide 34 paragraphs that define how the IT security landscape has evo.docx
rovide 34 paragraphs that define how the IT security landscape has evo.docxrovide 34 paragraphs that define how the IT security landscape has evo.docx
rovide 34 paragraphs that define how the IT security landscape has evo.docx
acarolyn
 
Regarding intermolecular forces Sometimes London dispersion forces ou.docx
Regarding intermolecular forces  Sometimes London dispersion forces ou.docxRegarding intermolecular forces  Sometimes London dispersion forces ou.docx
Regarding intermolecular forces Sometimes London dispersion forces ou.docx
acarolyn
 
Questions 12-14 refer to the following aqueous solutions- (A) 1 M BaCl.docx
Questions 12-14 refer to the following aqueous solutions- (A) 1 M BaCl.docxQuestions 12-14 refer to the following aqueous solutions- (A) 1 M BaCl.docx
Questions 12-14 refer to the following aqueous solutions- (A) 1 M BaCl.docx
acarolyn
 
Reed Pentak a finance major has been following globalization and made.docx
Reed Pentak a finance major has been following globalization and made.docxReed Pentak a finance major has been following globalization and made.docx
Reed Pentak a finance major has been following globalization and made.docx
acarolyn
 
Redesign- Make a prediction relating heat to the movement of molecules.docx
Redesign- Make a prediction relating heat to the movement of molecules.docxRedesign- Make a prediction relating heat to the movement of molecules.docx
Redesign- Make a prediction relating heat to the movement of molecules.docx
acarolyn
 
Recycling and composting are important parts of an overall management.docx
Recycling and composting are important parts of an overall management.docxRecycling and composting are important parts of an overall management.docx
Recycling and composting are important parts of an overall management.docx
acarolyn
 
R5232- RS422- 20mA Current Loop and 1EE488 are typical standard interf.docx
R5232- RS422- 20mA Current Loop and 1EE488 are typical standard interf.docxR5232- RS422- 20mA Current Loop and 1EE488 are typical standard interf.docx
R5232- RS422- 20mA Current Loop and 1EE488 are typical standard interf.docx
acarolyn
 
RADIUS provides three services- authentication- authorization- and acc.docx
RADIUS provides three services- authentication- authorization- and acc.docxRADIUS provides three services- authentication- authorization- and acc.docx
RADIUS provides three services- authentication- authorization- and acc.docx
acarolyn
 
Question- Federal funding agencies must form committees to decide whic.docx
Question- Federal funding agencies must form committees to decide whic.docxQuestion- Federal funding agencies must form committees to decide whic.docx
Question- Federal funding agencies must form committees to decide whic.docx
acarolyn
 

More from acarolyn (18)

Research the issues that you might face as a network administrator whe.docx
Research the issues that you might face as a network administrator whe.docxResearch the issues that you might face as a network administrator whe.docx
Research the issues that you might face as a network administrator whe.docx
 
Reset Help By the Brnsted-Lowry definition- acids are proton donors an.docx
Reset Help By the Brnsted-Lowry definition- acids are proton donors an.docxReset Help By the Brnsted-Lowry definition- acids are proton donors an.docx
Reset Help By the Brnsted-Lowry definition- acids are proton donors an.docx
 
SECTION III- SHORT ANSWER (10 possible points) Please give a brief ans.docx
SECTION III- SHORT ANSWER (10 possible points) Please give a brief ans.docxSECTION III- SHORT ANSWER (10 possible points) Please give a brief ans.docx
SECTION III- SHORT ANSWER (10 possible points) Please give a brief ans.docx
 
Select a specific event that has recently occurred (within the last 30.docx
Select a specific event that has recently occurred (within the last 30.docxSelect a specific event that has recently occurred (within the last 30.docx
Select a specific event that has recently occurred (within the last 30.docx
 
Security Breaches and the Six Dumb Ideas Consider a recent (2014- 2015.docx
Security Breaches and the Six Dumb Ideas Consider a recent (2014- 2015.docxSecurity Breaches and the Six Dumb Ideas Consider a recent (2014- 2015.docx
Security Breaches and the Six Dumb Ideas Consider a recent (2014- 2015.docx
 
Scientifically continuous phase apersed phase Speaking Chapter Review.docx
Scientifically continuous phase apersed phase Speaking Chapter Review.docxScientifically continuous phase apersed phase Speaking Chapter Review.docx
Scientifically continuous phase apersed phase Speaking Chapter Review.docx
 
Scenario- You are the Accountant for WanneBee Corporation WannaBee Cor.docx
Scenario- You are the Accountant for WanneBee Corporation WannaBee Cor.docxScenario- You are the Accountant for WanneBee Corporation WannaBee Cor.docx
Scenario- You are the Accountant for WanneBee Corporation WannaBee Cor.docx
 
Scenario Allen Manesfield- Jenny Winters- and John Jacobsen have been.docx
Scenario Allen Manesfield- Jenny Winters- and John Jacobsen have been.docxScenario Allen Manesfield- Jenny Winters- and John Jacobsen have been.docx
Scenario Allen Manesfield- Jenny Winters- and John Jacobsen have been.docx
 
S10-2 (Learning Objective 1- Describe the authority structure in a cor.docx
S10-2 (Learning Objective 1- Describe the authority structure in a cor.docxS10-2 (Learning Objective 1- Describe the authority structure in a cor.docx
S10-2 (Learning Objective 1- Describe the authority structure in a cor.docx
 
rovide 34 paragraphs that define how the IT security landscape has evo.docx
rovide 34 paragraphs that define how the IT security landscape has evo.docxrovide 34 paragraphs that define how the IT security landscape has evo.docx
rovide 34 paragraphs that define how the IT security landscape has evo.docx
 
Regarding intermolecular forces Sometimes London dispersion forces ou.docx
Regarding intermolecular forces  Sometimes London dispersion forces ou.docxRegarding intermolecular forces  Sometimes London dispersion forces ou.docx
Regarding intermolecular forces Sometimes London dispersion forces ou.docx
 
Questions 12-14 refer to the following aqueous solutions- (A) 1 M BaCl.docx
Questions 12-14 refer to the following aqueous solutions- (A) 1 M BaCl.docxQuestions 12-14 refer to the following aqueous solutions- (A) 1 M BaCl.docx
Questions 12-14 refer to the following aqueous solutions- (A) 1 M BaCl.docx
 
Reed Pentak a finance major has been following globalization and made.docx
Reed Pentak a finance major has been following globalization and made.docxReed Pentak a finance major has been following globalization and made.docx
Reed Pentak a finance major has been following globalization and made.docx
 
Redesign- Make a prediction relating heat to the movement of molecules.docx
Redesign- Make a prediction relating heat to the movement of molecules.docxRedesign- Make a prediction relating heat to the movement of molecules.docx
Redesign- Make a prediction relating heat to the movement of molecules.docx
 
Recycling and composting are important parts of an overall management.docx
Recycling and composting are important parts of an overall management.docxRecycling and composting are important parts of an overall management.docx
Recycling and composting are important parts of an overall management.docx
 
R5232- RS422- 20mA Current Loop and 1EE488 are typical standard interf.docx
R5232- RS422- 20mA Current Loop and 1EE488 are typical standard interf.docxR5232- RS422- 20mA Current Loop and 1EE488 are typical standard interf.docx
R5232- RS422- 20mA Current Loop and 1EE488 are typical standard interf.docx
 
RADIUS provides three services- authentication- authorization- and acc.docx
RADIUS provides three services- authentication- authorization- and acc.docxRADIUS provides three services- authentication- authorization- and acc.docx
RADIUS provides three services- authentication- authorization- and acc.docx
 
Question- Federal funding agencies must form committees to decide whic.docx
Question- Federal funding agencies must form committees to decide whic.docxQuestion- Federal funding agencies must form committees to decide whic.docx
Question- Federal funding agencies must form committees to decide whic.docx
 

Recently uploaded

Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
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
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
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
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
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
 
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
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
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
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 

Recently uploaded (20)

Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
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
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
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.
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
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
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
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
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 

reverse the linked list (2-4-8-10) by- stack- iteration- recursion- U.docx

  • 1. reverse the linked list (2,4,8,10) by: stack; iteration; recursion. Using C++ Solution #include<iostream> #include<stdio.h> #include<stdlib.h> #includ<stack> using namespace std; struct Node { int value; struct Node* next; }node; struct Node* reverse(struct Node* head) {Â Â // Iteration Method struct Node* current,*prev; current = head;
  • 2. prev = NULL; while(current!=NULL) { next = current->next; current->next = prev; prev = current; current = next; } head = prev;- return head; } struct Node* insert(Node* head,int value) { Node* temp = (struct Node*)malloc(sizeof(struct Node)); temp->value = value; temp->next = NULL; if(head = = NULL) head = temp; else { Node*temp1=head; while(temp1->next!=NULL) temp1 = temp1->next; temp1->next = temp; } return head; } public void print(Node* head) { while(head!=NULL) {
  • 3. cout<<head->value; head = head->next; } } struct Node*recursiveReverse(struct Node* &head) {Â Â //Recursion method if(head==NULL || head->next ==NULL) return; Node*first = head; Node *rest = head->next; if(rest !=NULL) return; recursiveReverse(rest); first ->next->next = first; first->next =NULL; head = rest; return head; } void Reverse(struct Node* head)Â Â // stack Implementation { stack<node*> Stack; node *traverse = head; while(traverse!=NULL) { Stack.push(traverse); traverse = traverse->next;Â Â } node *temp = Stack.top(); head = temp; Stack.pop();
  • 4. while(!Stack.empty()) { temp->next = Stack.top(); Stack.pop(); temp = temp->next;Â Â } temp->next = NULL; return Stack; } int main() { struct Node* head =NULL; head = insert(head,2); head = insert(head,4); head = insert(head,8); head = insert(head,10); print(head); head= reverse(head); print(head); head = recursiveReverse(head); print(head); head = void Reverse(head); void print(head); return 0; }