SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

Similar a 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
 

Similar a 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
 

Más de 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
 

Más de 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
 

Último

ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleCeline George
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataBabyAnnMotar
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...DhatriParmar
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 

Último (20)

ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP Module
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Measures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped dataMeasures of Position DECILES for ungrouped data
Measures of Position DECILES for ungrouped data
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 

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