SlideShare a Scribd company logo
1 of 2
Download to read offline
1) Create a function called reverselist that will take a simple list as a parameter and return the
reversed list. (We aren’t using the word reverse, since it is also the name of a built-in function.)
2) Create a function called deleteall that will take an item and a list as parameters, and return the
list with that item removed.
Solution
Hi, Please find my function.
Please let me know in case of any issue.
Let assume structure of node is:
/* Link list node */
struct node
{
int data;
struct node* next;
};
a)
/* Function to reverse the linked list */
struct node* reverse(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;
}
return prev;
}
b)
struct node* deleteNode(struct node *head, int item)
{
if(head == NULL)
return NULL;
// When node to be deleted is head node
if(head->data == item)
{
return head->next;
}
// When not first node, follow the normal deletion process
// find the previous node
struct node *prev = head;
while(prev->next != NULL && prev->item != item)
prev = prev->next;
// Check if node really exists in Linked List
if(prev->next == NULL)
{
printf(" Given node is not present in Linked List");
}else{
// Remove node from Linked List
prev->next = prev->next->next;
}
return head;
}

More Related Content

Similar to 1) Create a function called reverselist that will take a simple list.pdf

Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
rohit219406
 
To complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdfTo complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdf
ezycolours78
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
EricvtJFraserr
 
The algorithm to reverse a linked list by rearranging the required p.pdf
The algorithm to reverse a linked list by rearranging the required p.pdfThe algorithm to reverse a linked list by rearranging the required p.pdf
The algorithm to reverse a linked list by rearranging the required p.pdf
aradhana9856
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
rozakashif85
 
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdfin Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
sauravmanwanicp
 
Write a program in C that does the followinga) Builds a simple li.pdf
Write a program in C that does the followinga) Builds a simple li.pdfWrite a program in C that does the followinga) Builds a simple li.pdf
Write a program in C that does the followinga) Builds a simple li.pdf
kavithaarp
 
How to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfHow to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdf
arihantelehyb
 
Lec3-Linked list.pptx
Lec3-Linked list.pptxLec3-Linked list.pptx
Lec3-Linked list.pptx
FaheemMahmood2
 
Use C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdfUse C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdf
shalins6
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
Conint29
 
I need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdfI need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdf
sauravmanwanicp
 
Once you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docxOnce you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docx
farrahkur54
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdf
nitinarora01
 

Similar to 1) Create a function called reverselist that will take a simple list.pdf (20)

Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
 
To complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdfTo complete the task, you need to fill in the missing code. I’ve inc.pdf
To complete the task, you need to fill in the missing code. I’ve inc.pdf
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
The algorithm to reverse a linked list by rearranging the required p.pdf
The algorithm to reverse a linked list by rearranging the required p.pdfThe algorithm to reverse a linked list by rearranging the required p.pdf
The algorithm to reverse a linked list by rearranging the required p.pdf
 
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdfWrite a Java Class to Implement a Generic Linked ListYour list mus.pdf
Write a Java Class to Implement a Generic Linked ListYour list mus.pdf
 
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdfin Java (ignore the last line thats hidden) Create a doubly linked l.pdf
in Java (ignore the last line thats hidden) Create a doubly linked l.pdf
 
CSE240 Doubly Linked Lists
CSE240 Doubly Linked ListsCSE240 Doubly Linked Lists
CSE240 Doubly Linked Lists
 
Write a program in C that does the followinga) Builds a simple li.pdf
Write a program in C that does the followinga) Builds a simple li.pdfWrite a program in C that does the followinga) Builds a simple li.pdf
Write a program in C that does the followinga) Builds a simple li.pdf
 
How to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdfHow to do insertion sort on a singly linked list with no header usin.pdf
How to do insertion sort on a singly linked list with no header usin.pdf
 
Lec3-Linked list.pptx
Lec3-Linked list.pptxLec3-Linked list.pptx
Lec3-Linked list.pptx
 
Linked list1.ppt
Linked list1.pptLinked list1.ppt
Linked list1.ppt
 
Use C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdfUse C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdf
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
 
LinkedDoublyLists.ppt
LinkedDoublyLists.pptLinkedDoublyLists.ppt
LinkedDoublyLists.ppt
 
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
 
I need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdfI need help implementing a Stack with this java programming assignme.pdf
I need help implementing a Stack with this java programming assignme.pdf
 
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
 
Once you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docxOnce you have all the structures working as intended- it is time to co.docx
Once you have all the structures working as intended- it is time to co.docx
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdf
 
Data structures
Data structuresData structures
Data structures
 

More from ivylinvaydak64229

Every year, the viral strains included in vaccinations for the flu a.pdf
Every year, the viral strains included in vaccinations for the flu a.pdfEvery year, the viral strains included in vaccinations for the flu a.pdf
Every year, the viral strains included in vaccinations for the flu a.pdf
ivylinvaydak64229
 
Describe the role of different types of genomic changes in the evolut.pdf
Describe the role of different types of genomic changes in the evolut.pdfDescribe the role of different types of genomic changes in the evolut.pdf
Describe the role of different types of genomic changes in the evolut.pdf
ivylinvaydak64229
 
Analyze the detected attacks and create a report that describes each.pdf
Analyze the detected attacks and create a report that describes each.pdfAnalyze the detected attacks and create a report that describes each.pdf
Analyze the detected attacks and create a report that describes each.pdf
ivylinvaydak64229
 
Collect 50 or more paired quantitative data items. You may use a met.pdf
Collect 50 or more paired quantitative data items. You may use a met.pdfCollect 50 or more paired quantitative data items. You may use a met.pdf
Collect 50 or more paired quantitative data items. You may use a met.pdf
ivylinvaydak64229
 
Assume you have decided to implement DFS so remote sites can access .pdf
Assume you have decided to implement DFS so remote sites can access .pdfAssume you have decided to implement DFS so remote sites can access .pdf
Assume you have decided to implement DFS so remote sites can access .pdf
ivylinvaydak64229
 
A New Look at Bread and RosesIn Bread and Roses, Bruce Watson argu.pdf
A New Look at Bread and RosesIn Bread and Roses, Bruce Watson argu.pdfA New Look at Bread and RosesIn Bread and Roses, Bruce Watson argu.pdf
A New Look at Bread and RosesIn Bread and Roses, Bruce Watson argu.pdf
ivylinvaydak64229
 
A protein, called PHD (protein for retinoblastoma) a synthesized by a.pdf
A protein, called PHD (protein for retinoblastoma) a synthesized by a.pdfA protein, called PHD (protein for retinoblastoma) a synthesized by a.pdf
A protein, called PHD (protein for retinoblastoma) a synthesized by a.pdf
ivylinvaydak64229
 
What were the driving forces behind the creation of the FAA and ICAO.pdf
What were the driving forces behind the creation of the FAA and ICAO.pdfWhat were the driving forces behind the creation of the FAA and ICAO.pdf
What were the driving forces behind the creation of the FAA and ICAO.pdf
ivylinvaydak64229
 
write two paragraphs on the polices to reduce income inequality and .pdf
write two paragraphs on the polices to reduce income inequality and .pdfwrite two paragraphs on the polices to reduce income inequality and .pdf
write two paragraphs on the polices to reduce income inequality and .pdf
ivylinvaydak64229
 

More from ivylinvaydak64229 (20)

For the hypothesis test H0 = 5 against H1 5 with variance unkn.pdf
For the hypothesis test H0  = 5 against H1   5 with variance unkn.pdfFor the hypothesis test H0  = 5 against H1   5 with variance unkn.pdf
For the hypothesis test H0 = 5 against H1 5 with variance unkn.pdf
 
Early in 2017 scientists have discovered a new family of eukaryotic b.pdf
Early in 2017 scientists have discovered a new family of eukaryotic b.pdfEarly in 2017 scientists have discovered a new family of eukaryotic b.pdf
Early in 2017 scientists have discovered a new family of eukaryotic b.pdf
 
Do you believe great leaders are born or madeSolutioni believe.pdf
Do you believe great leaders are born or madeSolutioni believe.pdfDo you believe great leaders are born or madeSolutioni believe.pdf
Do you believe great leaders are born or madeSolutioni believe.pdf
 
Every year, the viral strains included in vaccinations for the flu a.pdf
Every year, the viral strains included in vaccinations for the flu a.pdfEvery year, the viral strains included in vaccinations for the flu a.pdf
Every year, the viral strains included in vaccinations for the flu a.pdf
 
Describe the role of different types of genomic changes in the evolut.pdf
Describe the role of different types of genomic changes in the evolut.pdfDescribe the role of different types of genomic changes in the evolut.pdf
Describe the role of different types of genomic changes in the evolut.pdf
 
Describe the Darwinian theory of evolutionDescribe the Darwi.pdf
Describe the Darwinian theory of evolutionDescribe the Darwi.pdfDescribe the Darwinian theory of evolutionDescribe the Darwi.pdf
Describe the Darwinian theory of evolutionDescribe the Darwi.pdf
 
Consider any organization where you’ve worked in the past, where you.pdf
Consider any organization where you’ve worked in the past, where you.pdfConsider any organization where you’ve worked in the past, where you.pdf
Consider any organization where you’ve worked in the past, where you.pdf
 
Analyze the detected attacks and create a report that describes each.pdf
Analyze the detected attacks and create a report that describes each.pdfAnalyze the detected attacks and create a report that describes each.pdf
Analyze the detected attacks and create a report that describes each.pdf
 
Collect 50 or more paired quantitative data items. You may use a met.pdf
Collect 50 or more paired quantitative data items. You may use a met.pdfCollect 50 or more paired quantitative data items. You may use a met.pdf
Collect 50 or more paired quantitative data items. You may use a met.pdf
 
Assume you have decided to implement DFS so remote sites can access .pdf
Assume you have decided to implement DFS so remote sites can access .pdfAssume you have decided to implement DFS so remote sites can access .pdf
Assume you have decided to implement DFS so remote sites can access .pdf
 
Are the following events SOURCES or USES of cashDecrease in Accou.pdf
Are the following events SOURCES or USES of cashDecrease in Accou.pdfAre the following events SOURCES or USES of cashDecrease in Accou.pdf
Are the following events SOURCES or USES of cashDecrease in Accou.pdf
 
A. What are two advantages that the use of green fluorescent protein.pdf
A. What are two advantages that the use of green fluorescent protein.pdfA. What are two advantages that the use of green fluorescent protein.pdf
A. What are two advantages that the use of green fluorescent protein.pdf
 
A species has a diploid number of 2n. Meiosis I fails during spermato.pdf
A species has a diploid number of 2n. Meiosis I fails during spermato.pdfA species has a diploid number of 2n. Meiosis I fails during spermato.pdf
A species has a diploid number of 2n. Meiosis I fails during spermato.pdf
 
A New Look at Bread and RosesIn Bread and Roses, Bruce Watson argu.pdf
A New Look at Bread and RosesIn Bread and Roses, Bruce Watson argu.pdfA New Look at Bread and RosesIn Bread and Roses, Bruce Watson argu.pdf
A New Look at Bread and RosesIn Bread and Roses, Bruce Watson argu.pdf
 
A protein, called PHD (protein for retinoblastoma) a synthesized by a.pdf
A protein, called PHD (protein for retinoblastoma) a synthesized by a.pdfA protein, called PHD (protein for retinoblastoma) a synthesized by a.pdf
A protein, called PHD (protein for retinoblastoma) a synthesized by a.pdf
 
What were the driving forces behind the creation of the FAA and ICAO.pdf
What were the driving forces behind the creation of the FAA and ICAO.pdfWhat were the driving forces behind the creation of the FAA and ICAO.pdf
What were the driving forces behind the creation of the FAA and ICAO.pdf
 
write two paragraphs on the polices to reduce income inequality and .pdf
write two paragraphs on the polices to reduce income inequality and .pdfwrite two paragraphs on the polices to reduce income inequality and .pdf
write two paragraphs on the polices to reduce income inequality and .pdf
 
Where might you find the gametophytes of… Where might you find the g.pdf
Where might you find the gametophytes of… Where might you find the g.pdfWhere might you find the gametophytes of… Where might you find the g.pdf
Where might you find the gametophytes of… Where might you find the g.pdf
 
What single , unique characteristic of a protist would be conside.pdf
What single , unique characteristic of a protist would be conside.pdfWhat single , unique characteristic of a protist would be conside.pdf
What single , unique characteristic of a protist would be conside.pdf
 
What are the indications that Sarcodina, Apicomplexa and Ciliophora .pdf
What are the indications that Sarcodina, Apicomplexa and Ciliophora .pdfWhat are the indications that Sarcodina, Apicomplexa and Ciliophora .pdf
What are the indications that Sarcodina, Apicomplexa and Ciliophora .pdf
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 

Recently uploaded (20)

How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 

1) Create a function called reverselist that will take a simple list.pdf

  • 1. 1) Create a function called reverselist that will take a simple list as a parameter and return the reversed list. (We aren’t using the word reverse, since it is also the name of a built-in function.) 2) Create a function called deleteall that will take an item and a list as parameters, and return the list with that item removed. Solution Hi, Please find my function. Please let me know in case of any issue. Let assume structure of node is: /* Link list node */ struct node { int data; struct node* next; }; a) /* Function to reverse the linked list */ struct node* reverse(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; } return prev; } b) struct node* deleteNode(struct node *head, int item) {
  • 2. if(head == NULL) return NULL; // When node to be deleted is head node if(head->data == item) { return head->next; } // When not first node, follow the normal deletion process // find the previous node struct node *prev = head; while(prev->next != NULL && prev->item != item) prev = prev->next; // Check if node really exists in Linked List if(prev->next == NULL) { printf(" Given node is not present in Linked List"); }else{ // Remove node from Linked List prev->next = prev->next->next; } return head; }