SlideShare ist ein Scribd-Unternehmen logo
1 von 3
coding in C;
Create a function called reverseList that takes the head of a linked list, reverses the order of all
the nodes. For example, if the list contained 1, 2, 3, 4 in its nodes, the list will now contain 4, 3,
2, 1.
please add a main test.
Solution
Please find the required program below:
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node* next;
};
void push(struct node** head, int new_element)
{
struct node* new_node =
(struct node*) malloc(sizeof(struct node));
new_node->data = new_element;
new_node->next = (*head);
(*head) = new_node;
}
void printList(struct node *head)
{
struct node *temp = head;
while(temp != NULL)
{
printf("%d ", temp->data);
temp = temp->next;
}
}
void reverseList(struct node** head)
{
struct node* prev = NULL;
struct node* current = *head;
struct node* next;
while (current != NULL)
{
next = current->next;
current->next = prev;
prev = current;
current = next;
}
*head = prev;
}
int main()
{
struct node* head = NULL;
push(&head, 12);
push(&head, 14);
push(&head, 5);
push(&head, 8);
printf(" Linked list Before Reversing : ");
printList(head);
reverseList(&head);
printf(" Linked list After Reversing : ");
printList(head);
}
--------------------------------------------------------------------------------
OUTPUT:
Linked list Before Reversing :
8Â Â 5Â Â 14Â Â 12
Linked list After Reversing :
12Â Â 14Â Â 5Â Â 8

Weitere ähnliche Inhalte

Ähnlich wie coding in C- Create a function called reverseList that takes the head.docx

Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfJUSTSTYLISH3B2MOHALI
 
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.docxnoreendchesterton753
 
Create a C program which auto-completes suggestions when beginning t.pdf
Create a C program which auto-completes suggestions when beginning t.pdfCreate a C program which auto-completes suggestions when beginning t.pdf
Create a C program which auto-completes suggestions when beginning t.pdffedosys
 
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
 
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
 
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
 
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
 
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfformicreation
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYMalikireddy Bramhananda Reddy
 
Write a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdfWrite a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdfSANDEEPARIHANT
 
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
 
#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdflakshmijewellery
 
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdfC++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdffeelinggift
 

Ähnlich wie coding in C- Create a function called reverseList that takes the head.docx (20)

Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 
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
 
Create a C program which auto-completes suggestions when beginning t.pdf
Create a C program which auto-completes suggestions when beginning t.pdfCreate a C program which auto-completes suggestions when beginning t.pdf
Create a C program which auto-completes suggestions when beginning t.pdf
 
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
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
 
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
 
C Assignment Help
C Assignment HelpC Assignment Help
C Assignment Help
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
137 Lab-2.2.pdf
137 Lab-2.2.pdf137 Lab-2.2.pdf
137 Lab-2.2.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
 
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
 
Linked list
Linked listLinked list
Linked list
 
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
 
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdfAssignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
Assignment is Page 349-350 #4 and #5 Use the Linked Lis.pdf
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
 
Write a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdfWrite a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.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
 
#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf
 
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdfC++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
C++ projectMachine Problem 7 - HashingWrite a program to do the .pdf
 

Mehr von tienlivick

The long-term liability section of Twin Digital Corporation's balance.docx
The long-term liability section of Twin Digital Corporation's balance.docxThe long-term liability section of Twin Digital Corporation's balance.docx
The long-term liability section of Twin Digital Corporation's balance.docxtienlivick
 
The length of time- in minutes- for an airplane to obtain clearance fo.docx
The length of time- in minutes- for an airplane to obtain clearance fo.docxThe length of time- in minutes- for an airplane to obtain clearance fo.docx
The length of time- in minutes- for an airplane to obtain clearance fo.docxtienlivick
 
The Kansas Early Learning Standards for Social and Emotional Developme.docx
The Kansas Early Learning Standards for Social and Emotional Developme.docxThe Kansas Early Learning Standards for Social and Emotional Developme.docx
The Kansas Early Learning Standards for Social and Emotional Developme.docxtienlivick
 
The Italian economy can be characterized by the following information-.docx
The Italian economy can be characterized by the following information-.docxThe Italian economy can be characterized by the following information-.docx
The Italian economy can be characterized by the following information-.docxtienlivick
 
The individual that reports to the respective discipline manager- and.docx
The individual that reports to the respective discipline manager- and.docxThe individual that reports to the respective discipline manager- and.docx
The individual that reports to the respective discipline manager- and.docxtienlivick
 
The Implementation The unique requirement for the SpecializedList is t.docx
The Implementation The unique requirement for the SpecializedList is t.docxThe Implementation The unique requirement for the SpecializedList is t.docx
The Implementation The unique requirement for the SpecializedList is t.docxtienlivick
 
The imount liay ned to put aiay loday a f (Riound 13 en nemest cent).docx
The imount liay ned to put aiay loday a f (Riound 13 en nemest cent).docxThe imount liay ned to put aiay loday a f (Riound 13 en nemest cent).docx
The imount liay ned to put aiay loday a f (Riound 13 en nemest cent).docxtienlivick
 
The hepcidin hormone acts as a negative regulator of iron absorption-.docx
The hepcidin hormone acts as a negative regulator of iron absorption-.docxThe hepcidin hormone acts as a negative regulator of iron absorption-.docx
The hepcidin hormone acts as a negative regulator of iron absorption-.docxtienlivick
 
The Hardy-Weinberg principleapplies to which populations- Populations.docx
The Hardy-Weinberg principleapplies to which populations- Populations.docxThe Hardy-Weinberg principleapplies to which populations- Populations.docx
The Hardy-Weinberg principleapplies to which populations- Populations.docxtienlivick
 
The Giant Kelp forests of the US Pacific coast have really cold water-.docx
The Giant Kelp forests of the US Pacific coast have really cold water-.docxThe Giant Kelp forests of the US Pacific coast have really cold water-.docx
The Giant Kelp forests of the US Pacific coast have really cold water-.docxtienlivick
 
The function T(n) satisfies T(n)-2T(3n)+O(n2)- Which of the following.docx
The function T(n) satisfies T(n)-2T(3n)+O(n2)- Which of the following.docxThe function T(n) satisfies T(n)-2T(3n)+O(n2)- Which of the following.docx
The function T(n) satisfies T(n)-2T(3n)+O(n2)- Which of the following.docxtienlivick
 
The following table summarizes the ages of a sample of 57 adults that.docx
The following table summarizes the ages of a sample of 57 adults that.docxThe following table summarizes the ages of a sample of 57 adults that.docx
The following table summarizes the ages of a sample of 57 adults that.docxtienlivick
 
The following table presents output per hour in the country of Mistani.docx
The following table presents output per hour in the country of Mistani.docxThe following table presents output per hour in the country of Mistani.docx
The following table presents output per hour in the country of Mistani.docxtienlivick
 
The following selected transactions occurred during 2024 and 2025 for.docx
The following selected transactions occurred during 2024 and 2025 for.docxThe following selected transactions occurred during 2024 and 2025 for.docx
The following selected transactions occurred during 2024 and 2025 for.docxtienlivick
 
The following refer to the following data set- What is the mean (x) of.docx
The following refer to the following data set- What is the mean (x) of.docxThe following refer to the following data set- What is the mean (x) of.docx
The following refer to the following data set- What is the mean (x) of.docxtienlivick
 
The following questions are based on the case study- The Human Right t.docx
The following questions are based on the case study- The Human Right t.docxThe following questions are based on the case study- The Human Right t.docx
The following questions are based on the case study- The Human Right t.docxtienlivick
 
The following items are taken from the financial statements of Pharoah.docx
The following items are taken from the financial statements of Pharoah.docxThe following items are taken from the financial statements of Pharoah.docx
The following items are taken from the financial statements of Pharoah.docxtienlivick
 
The following financial assets appeared in a recent balance sheet of A.docx
The following financial assets appeared in a recent balance sheet of A.docxThe following financial assets appeared in a recent balance sheet of A.docx
The following financial assets appeared in a recent balance sheet of A.docxtienlivick
 
The following graph shows an aggregate demand (AD) curve and a short-r.docx
The following graph shows an aggregate demand (AD) curve and a short-r.docxThe following graph shows an aggregate demand (AD) curve and a short-r.docx
The following graph shows an aggregate demand (AD) curve and a short-r.docxtienlivick
 
The first production department of Stone Incorporated reports the foll.docx
The first production department of Stone Incorporated reports the foll.docxThe first production department of Stone Incorporated reports the foll.docx
The first production department of Stone Incorporated reports the foll.docxtienlivick
 

Mehr von tienlivick (20)

The long-term liability section of Twin Digital Corporation's balance.docx
The long-term liability section of Twin Digital Corporation's balance.docxThe long-term liability section of Twin Digital Corporation's balance.docx
The long-term liability section of Twin Digital Corporation's balance.docx
 
The length of time- in minutes- for an airplane to obtain clearance fo.docx
The length of time- in minutes- for an airplane to obtain clearance fo.docxThe length of time- in minutes- for an airplane to obtain clearance fo.docx
The length of time- in minutes- for an airplane to obtain clearance fo.docx
 
The Kansas Early Learning Standards for Social and Emotional Developme.docx
The Kansas Early Learning Standards for Social and Emotional Developme.docxThe Kansas Early Learning Standards for Social and Emotional Developme.docx
The Kansas Early Learning Standards for Social and Emotional Developme.docx
 
The Italian economy can be characterized by the following information-.docx
The Italian economy can be characterized by the following information-.docxThe Italian economy can be characterized by the following information-.docx
The Italian economy can be characterized by the following information-.docx
 
The individual that reports to the respective discipline manager- and.docx
The individual that reports to the respective discipline manager- and.docxThe individual that reports to the respective discipline manager- and.docx
The individual that reports to the respective discipline manager- and.docx
 
The Implementation The unique requirement for the SpecializedList is t.docx
The Implementation The unique requirement for the SpecializedList is t.docxThe Implementation The unique requirement for the SpecializedList is t.docx
The Implementation The unique requirement for the SpecializedList is t.docx
 
The imount liay ned to put aiay loday a f (Riound 13 en nemest cent).docx
The imount liay ned to put aiay loday a f (Riound 13 en nemest cent).docxThe imount liay ned to put aiay loday a f (Riound 13 en nemest cent).docx
The imount liay ned to put aiay loday a f (Riound 13 en nemest cent).docx
 
The hepcidin hormone acts as a negative regulator of iron absorption-.docx
The hepcidin hormone acts as a negative regulator of iron absorption-.docxThe hepcidin hormone acts as a negative regulator of iron absorption-.docx
The hepcidin hormone acts as a negative regulator of iron absorption-.docx
 
The Hardy-Weinberg principleapplies to which populations- Populations.docx
The Hardy-Weinberg principleapplies to which populations- Populations.docxThe Hardy-Weinberg principleapplies to which populations- Populations.docx
The Hardy-Weinberg principleapplies to which populations- Populations.docx
 
The Giant Kelp forests of the US Pacific coast have really cold water-.docx
The Giant Kelp forests of the US Pacific coast have really cold water-.docxThe Giant Kelp forests of the US Pacific coast have really cold water-.docx
The Giant Kelp forests of the US Pacific coast have really cold water-.docx
 
The function T(n) satisfies T(n)-2T(3n)+O(n2)- Which of the following.docx
The function T(n) satisfies T(n)-2T(3n)+O(n2)- Which of the following.docxThe function T(n) satisfies T(n)-2T(3n)+O(n2)- Which of the following.docx
The function T(n) satisfies T(n)-2T(3n)+O(n2)- Which of the following.docx
 
The following table summarizes the ages of a sample of 57 adults that.docx
The following table summarizes the ages of a sample of 57 adults that.docxThe following table summarizes the ages of a sample of 57 adults that.docx
The following table summarizes the ages of a sample of 57 adults that.docx
 
The following table presents output per hour in the country of Mistani.docx
The following table presents output per hour in the country of Mistani.docxThe following table presents output per hour in the country of Mistani.docx
The following table presents output per hour in the country of Mistani.docx
 
The following selected transactions occurred during 2024 and 2025 for.docx
The following selected transactions occurred during 2024 and 2025 for.docxThe following selected transactions occurred during 2024 and 2025 for.docx
The following selected transactions occurred during 2024 and 2025 for.docx
 
The following refer to the following data set- What is the mean (x) of.docx
The following refer to the following data set- What is the mean (x) of.docxThe following refer to the following data set- What is the mean (x) of.docx
The following refer to the following data set- What is the mean (x) of.docx
 
The following questions are based on the case study- The Human Right t.docx
The following questions are based on the case study- The Human Right t.docxThe following questions are based on the case study- The Human Right t.docx
The following questions are based on the case study- The Human Right t.docx
 
The following items are taken from the financial statements of Pharoah.docx
The following items are taken from the financial statements of Pharoah.docxThe following items are taken from the financial statements of Pharoah.docx
The following items are taken from the financial statements of Pharoah.docx
 
The following financial assets appeared in a recent balance sheet of A.docx
The following financial assets appeared in a recent balance sheet of A.docxThe following financial assets appeared in a recent balance sheet of A.docx
The following financial assets appeared in a recent balance sheet of A.docx
 
The following graph shows an aggregate demand (AD) curve and a short-r.docx
The following graph shows an aggregate demand (AD) curve and a short-r.docxThe following graph shows an aggregate demand (AD) curve and a short-r.docx
The following graph shows an aggregate demand (AD) curve and a short-r.docx
 
The first production department of Stone Incorporated reports the foll.docx
The first production department of Stone Incorporated reports the foll.docxThe first production department of Stone Incorporated reports the foll.docx
The first production department of Stone Incorporated reports the foll.docx
 

Kürzlich hochgeladen

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
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
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
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
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 

Kürzlich hochgeladen (20)

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
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
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
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 ...
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
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
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 

coding in C- Create a function called reverseList that takes the head.docx

  • 1. coding in C; Create a function called reverseList that takes the head of a linked list, reverses the order of all the nodes. For example, if the list contained 1, 2, 3, 4 in its nodes, the list will now contain 4, 3, 2, 1. please add a main test. Solution Please find the required program below: #include<stdio.h> #include<stdlib.h> struct node { int data; struct node* next; }; void push(struct node** head, int new_element) { struct node* new_node = (struct node*) malloc(sizeof(struct node)); new_node->data = new_element; new_node->next = (*head); (*head) = new_node; } void printList(struct node *head) { struct node *temp = head;
  • 2. while(temp != NULL) { printf("%d ", temp->data); temp = temp->next; } } void reverseList(struct node** head) { struct node* prev = NULL; struct node* current = *head; struct node* next; while (current != NULL) { next = current->next; current->next = prev; prev = current; current = next; } *head = prev; } int main() { struct node* head = NULL; push(&head, 12); push(&head, 14); push(&head, 5); push(&head, 8); printf(" Linked list Before Reversing : "); printList(head); reverseList(&head); printf(" Linked list After Reversing : "); printList(head); } -------------------------------------------------------------------------------- OUTPUT: Linked list Before Reversing : 8Â Â 5Â Â 14Â Â 12 Linked list After Reversing :
  • 3. 12Â Â 14Â Â 5Â Â 8