SlideShare a Scribd company logo
Please code in C language. Please do part 1 and 2. Do not recycle answers and implement the
starter code
Starter code:
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "linkedlist.h"
// print an error message by an error number, and return
// the function does not exit from the program
// the function does not return a value
void error_message(enum ErrorNumber errno) {
char *messages[] = {
"OK",
"Memory allocaton failed.",
"Deleting a node is not supported.",
"The number is not on the list.",
"Sorting is not supported.",
"Reversing is not supported.",
"Token is too long.",
"A number should be specified after character d, a, or p.",
"Token is not recognized.",
"Invalid error number."};
if (errno < 0 || errno > ERR_END)
errno = ERR_END;
printf("linkedlist: %sn", messages[errno]);
}
node *new_node(int v) {
node *p = malloc(sizeof(node)); // Allocate memory
if (p == NULL) {
error_message(ERR_NOMEM);
exit(-1);
}
// Set the value in the node.
p->v = v; // you could do (*p).v
p->next = NULL;
return p; // return
}
node *prepend(node *head, node *newnode) {
newnode->next = head;
return newnode;
}
node *find_node(node *head, int v) {
while (head != NULL) {
if (head->v == v)
return head;
head = head->next;
}
return head;
}
node *find_last(node *head) {
if (head != NULL) {
while (head->next != NULL)
head = head->next;
}
return head;
}
node *append(node *head, node *newnode) {
node *p = find_last(head);
newnode->next = NULL;
if (p == NULL)
return newnode;
p->next = newnode;
return head;
}
node *delete_list(node *head) {
while (head != NULL) {
node *p = head->next;
free(head);
head = p;
}
return head;
}
void print_list(node *head) {
printf("[");
while (head) {
printf("%d, ", head->v);
head = head->next;
}
printf("]n");
}
void print_node(node *p) {
printf("%p: v=%-5d next=%pn", p, p->v, p->next);
}
void print_list_details(node *head) {
while (head) {
print_node(head);
head = head->next;
}
}
// functions that have not been implemented
node *delete_node(node *head, int v) {
// TODO
error_message(ERR_NODELETE);
return head;
}
/*
* Given a pointer to the head node of an acyclic list, change the
* next links such that the nodes are linked in reverse order.
* Allocating new nodes or copying values from one node to another
* is not allowed, but you may use additional pointer variables.
* Return value is a pointer to the new head node.
*/
node *reverse_list(node *head) {
// TODO
error_message(ERR_NOREVERSE);
return head;
}
Part 1. Delete node. The linked list example we have studied in lecture maintains a singly linked
list of integers. The program can append and prepend integers to the list. Type help in the
program to see a list of commands. Note that if the number to be added is already on the list, the
program prints the information about the node that stores the number and does not add the
number twice. The list is displayed every time an integer is processed. Currently, the program
does not support the delete function. Complete the function delete.node() in linkedlist. c so that
the program can delete an integer from the list. The prototype of the function is: [ text { node }
* text { delete_node(node } * text { head, int v); } ] head is a pointer to the head node and v is
the integer to be removed. The function returns the pointer to the head node of the new list,
which could be the same as head. If v is not on the list, the function prints a message using the
following function call: error_message(ERR_NOTFOUND). Below is an example session using
the delete feature. $ ./1inkedlist-main 123456789 [ 1 , [ 1 , 2 , [ 1 , 2 , 3 , [ 1 , 2 , 3 , 4 , [ 1 , 2 , 3 ,
4 , 5 , [ 1 , 2 , 3 , 4 , 5 , 6 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , [ 1 , 2 , 3 , 4 , 5 , 6 ,
7 , 8 , 9 , d5 [ 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 , d3 [ 1 , 2 , 4 , 6 , 7 , 8 , 9 , d3 linkedlist: The number is not
on the list. [ 1 , 2 , 4 , 6 , 7 , 8 , 9 , Part 2. List reversal. In this exercise, we implement another
function reverse_list () in linkedlist. The prototype of the function is: [ text { node } * text {
reverse_list (node } * text { head); } ] The function receives head as its sole argument, a pointer
to the head node of the linked list. Assun the list is acyclic. The function must change the next
fields of each node so that the nodes end up link in reverse order. The function must return the
address of the new head node (originally last in the list You may use additional functions and
local variables besides those already included in the starter code, b cannot change the values
stored in the nodes or dynamically allocate new nodes. You can use either a lod or recursion.
Below is an example session using the reversal feature. $./ linkedlist-main 1234556789 [ 1 , [ 1 ,
2 , [ 1 , 2 , 3 , [ 1 , 2 , 3 , 4 , [ 1 , 2 , 3 , 4 , 5 , [ 1 , 2 , 3 , 4 , 5 , 6 ,

More Related Content

Similar to Please code in C language- Please do part 1 and 2- Do not recycle answ.docx

Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdfMerge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdfmdameer02
 
For this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdfFor this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdfherminaherman
 
PE1 Module 4.ppt
PE1 Module 4.pptPE1 Module 4.ppt
PE1 Module 4.pptbalewayalew
 
C++ code, please help! RESPOND W COMPLETED CODE PLEASE, am using V.pdf
C++ code, please help! RESPOND W COMPLETED CODE PLEASE,  am using V.pdfC++ code, please help! RESPOND W COMPLETED CODE PLEASE,  am using V.pdf
C++ code, please help! RESPOND W COMPLETED CODE PLEASE, am using V.pdfrahulfancycorner21
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloadingankush_kumar
 
C programming. Answer question only in C code Ninth Deletion with B.pdf
C programming. Answer question only in C code Ninth Deletion with B.pdfC programming. Answer question only in C code Ninth Deletion with B.pdf
C programming. Answer question only in C code Ninth Deletion with B.pdfinfo309708
 
Write the definition of the linkedListKeepLast function- (Please write.docx
Write the definition of the linkedListKeepLast function- (Please write.docxWrite the definition of the linkedListKeepLast function- (Please write.docx
Write the definition of the linkedListKeepLast function- (Please write.docxdelicecogupdyke
 
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..pdfrohit219406
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functionsmussawir20
 
please help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdfplease help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdfnewfaransportsfitnes
 
The best every notes on c language is here check it out
The best every notes on c language is here check it outThe best every notes on c language is here check it out
The best every notes on c language is here check it outrajatryadav22
 
Write java program using linked list to get integer from user and.docx
 Write java program using linked list to get integer from user and.docx Write java program using linked list to get integer from user and.docx
Write java program using linked list to get integer from user and.docxajoy21
 
pleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdfpleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdfwasemanivytreenrco51
 
9. DBMS Experiment Laboratory PresentationPPT
9. DBMS Experiment Laboratory PresentationPPT9. DBMS Experiment Laboratory PresentationPPT
9. DBMS Experiment Laboratory PresentationPPTTheVerse1
 
Im having trouble figuring out how to code these sections for an a.pdf
Im having trouble figuring out how to code these sections for an a.pdfIm having trouble figuring out how to code these sections for an a.pdf
Im having trouble figuring out how to code these sections for an a.pdfrishteygallery
 
C++ code, please help! Troubleshooting and cannot for the life of me.pdf
C++ code, please help! Troubleshooting and cannot for the life of me.pdfC++ code, please help! Troubleshooting and cannot for the life of me.pdf
C++ code, please help! Troubleshooting and cannot for the life of me.pdfrahulfancycorner21
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab ManualAkhilaaReddy
 

Similar to Please code in C language- Please do part 1 and 2- Do not recycle answ.docx (20)

Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdfMerge Sort implementation in C++ The implementation for Mergesort gi.pdf
Merge Sort implementation in C++ The implementation for Mergesort gi.pdf
 
For this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdfFor this homework, you will write a program to create and manipulate.pdf
For this homework, you will write a program to create and manipulate.pdf
 
PE1 Module 4.ppt
PE1 Module 4.pptPE1 Module 4.ppt
PE1 Module 4.ppt
 
C++ code, please help! RESPOND W COMPLETED CODE PLEASE, am using V.pdf
C++ code, please help! RESPOND W COMPLETED CODE PLEASE,  am using V.pdfC++ code, please help! RESPOND W COMPLETED CODE PLEASE,  am using V.pdf
C++ code, please help! RESPOND W COMPLETED CODE PLEASE, am using V.pdf
 
C Homework Help
C Homework HelpC Homework Help
C Homework Help
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
 
C programming. Answer question only in C code Ninth Deletion with B.pdf
C programming. Answer question only in C code Ninth Deletion with B.pdfC programming. Answer question only in C code Ninth Deletion with B.pdf
C programming. Answer question only in C code Ninth Deletion with B.pdf
 
C Programming
C ProgrammingC Programming
C Programming
 
Write the definition of the linkedListKeepLast function- (Please write.docx
Write the definition of the linkedListKeepLast function- (Please write.docxWrite the definition of the linkedListKeepLast function- (Please write.docx
Write the definition of the linkedListKeepLast function- (Please write.docx
 
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
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
 
please help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdfplease help me with this and explain in details also in the first qu.pdf
please help me with this and explain in details also in the first qu.pdf
 
The best every notes on c language is here check it out
The best every notes on c language is here check it outThe best every notes on c language is here check it out
The best every notes on c language is here check it out
 
Write java program using linked list to get integer from user and.docx
 Write java program using linked list to get integer from user and.docx Write java program using linked list to get integer from user and.docx
Write java program using linked list to get integer from user and.docx
 
pleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdfpleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdf
 
9. DBMS Experiment Laboratory PresentationPPT
9. DBMS Experiment Laboratory PresentationPPT9. DBMS Experiment Laboratory PresentationPPT
9. DBMS Experiment Laboratory PresentationPPT
 
Im having trouble figuring out how to code these sections for an a.pdf
Im having trouble figuring out how to code these sections for an a.pdfIm having trouble figuring out how to code these sections for an a.pdf
Im having trouble figuring out how to code these sections for an a.pdf
 
7 functions
7  functions7  functions
7 functions
 
C++ code, please help! Troubleshooting and cannot for the life of me.pdf
C++ code, please help! Troubleshooting and cannot for the life of me.pdfC++ code, please help! Troubleshooting and cannot for the life of me.pdf
C++ code, please help! Troubleshooting and cannot for the life of me.pdf
 
VTU DSA Lab Manual
VTU DSA Lab ManualVTU DSA Lab Manual
VTU DSA Lab Manual
 

More from cgraciela1

PLEASE HELP The above table shows the annual incomes of individuals.docx
PLEASE HELP   The above table shows the annual incomes of individuals.docxPLEASE HELP   The above table shows the annual incomes of individuals.docx
PLEASE HELP The above table shows the annual incomes of individuals.docxcgraciela1
 
Please give examples on all of the following titles and solve them as.docx
Please give examples on all of the following titles and solve them as.docxPlease give examples on all of the following titles and solve them as.docx
Please give examples on all of the following titles and solve them as.docxcgraciela1
 
please give the answer please give the answer A product's life cycl.docx
please give the answer please give the answer    A product's life cycl.docxplease give the answer please give the answer    A product's life cycl.docx
please give the answer please give the answer A product's life cycl.docxcgraciela1
 
please give a details explanation- i tried but i keep getting erronou.docx
please give a details explanation-  i tried but i keep getting erronou.docxplease give a details explanation-  i tried but i keep getting erronou.docx
please give a details explanation- i tried but i keep getting erronou.docxcgraciela1
 
Please explain- Thank you! 3- Show intermediate steps of sorting the a.docx
Please explain- Thank you! 3- Show intermediate steps of sorting the a.docxPlease explain- Thank you! 3- Show intermediate steps of sorting the a.docx
Please explain- Thank you! 3- Show intermediate steps of sorting the a.docxcgraciela1
 
Please explain why the answer is B instead of D 5- Which of the follow.docx
Please explain why the answer is B instead of D 5- Which of the follow.docxPlease explain why the answer is B instead of D 5- Which of the follow.docx
Please explain why the answer is B instead of D 5- Which of the follow.docxcgraciela1
 
Please Drawing this numbers using python Draw these follow.docx
Please Drawing this numbers using python             Draw these follow.docxPlease Drawing this numbers using python             Draw these follow.docx
Please Drawing this numbers using python Draw these follow.docxcgraciela1
 
PLEASE don't copy and paste from a previous answer because it was inco.docx
PLEASE don't copy and paste from a previous answer because it was inco.docxPLEASE don't copy and paste from a previous answer because it was inco.docx
PLEASE don't copy and paste from a previous answer because it was inco.docxcgraciela1
 
Please draw concept map Cdc45 Cdc6 Cdt1 Clamp Clamp loader CMG comp.docx
Please draw concept map    Cdc45 Cdc6 Cdt1 Clamp Clamp loader CMG comp.docxPlease draw concept map    Cdc45 Cdc6 Cdt1 Clamp Clamp loader CMG comp.docx
Please draw concept map Cdc45 Cdc6 Cdt1 Clamp Clamp loader CMG comp.docxcgraciela1
 
Please dont copy paste a-What is customer service- b- Main theories o.docx
Please dont copy paste a-What is customer service-  b- Main theories o.docxPlease dont copy paste a-What is customer service-  b- Main theories o.docx
Please dont copy paste a-What is customer service- b- Main theories o.docxcgraciela1
 
PLEASE DONT COPY ANSWER Draw a DFA that accepts the strings that repre.docx
PLEASE DONT COPY ANSWER Draw a DFA that accepts the strings that repre.docxPLEASE DONT COPY ANSWER Draw a DFA that accepts the strings that repre.docx
PLEASE DONT COPY ANSWER Draw a DFA that accepts the strings that repre.docxcgraciela1
 
Please do this for me!! I would gladly appreciate it- Write one result.docx
Please do this for me!! I would gladly appreciate it- Write one result.docxPlease do this for me!! I would gladly appreciate it- Write one result.docx
Please do this for me!! I would gladly appreciate it- Write one result.docxcgraciela1
 
Please copy and paste the code and explain why it won't work- It is su.docx
Please copy and paste the code and explain why it won't work- It is su.docxPlease copy and paste the code and explain why it won't work- It is su.docx
Please copy and paste the code and explain why it won't work- It is su.docxcgraciela1
 
Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxcgraciela1
 
please ask and answer questions in internet technologies in the follo.docx
please ask and answer questions in  internet technologies in the follo.docxplease ask and answer questions in  internet technologies in the follo.docx
please ask and answer questions in internet technologies in the follo.docxcgraciela1
 
Please answer the multiple choice questions with detailed explanation.docx
Please answer the multiple choice questions with detailed explanation.docxPlease answer the multiple choice questions with detailed explanation.docx
Please answer the multiple choice questions with detailed explanation.docxcgraciela1
 
Please answer the following questions about the network of streets in.docx
Please answer the following questions about the network of streets in.docxPlease answer the following questions about the network of streets in.docx
Please answer the following questions about the network of streets in.docxcgraciela1
 
Please answer 16-29- thank you P4- Dissection of the Fetal Pig Ventr.docx
Please answer 16-29- thank you   P4- Dissection of the Fetal Pig Ventr.docxPlease answer 16-29- thank you   P4- Dissection of the Fetal Pig Ventr.docx
Please answer 16-29- thank you P4- Dissection of the Fetal Pig Ventr.docxcgraciela1
 
Please answer the 3 questions- Case Study 2 Too Much Fatigue and Stres.docx
Please answer the 3 questions- Case Study 2 Too Much Fatigue and Stres.docxPlease answer the 3 questions- Case Study 2 Too Much Fatigue and Stres.docx
Please answer the 3 questions- Case Study 2 Too Much Fatigue and Stres.docxcgraciela1
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxcgraciela1
 

More from cgraciela1 (20)

PLEASE HELP The above table shows the annual incomes of individuals.docx
PLEASE HELP   The above table shows the annual incomes of individuals.docxPLEASE HELP   The above table shows the annual incomes of individuals.docx
PLEASE HELP The above table shows the annual incomes of individuals.docx
 
Please give examples on all of the following titles and solve them as.docx
Please give examples on all of the following titles and solve them as.docxPlease give examples on all of the following titles and solve them as.docx
Please give examples on all of the following titles and solve them as.docx
 
please give the answer please give the answer A product's life cycl.docx
please give the answer please give the answer    A product's life cycl.docxplease give the answer please give the answer    A product's life cycl.docx
please give the answer please give the answer A product's life cycl.docx
 
please give a details explanation- i tried but i keep getting erronou.docx
please give a details explanation-  i tried but i keep getting erronou.docxplease give a details explanation-  i tried but i keep getting erronou.docx
please give a details explanation- i tried but i keep getting erronou.docx
 
Please explain- Thank you! 3- Show intermediate steps of sorting the a.docx
Please explain- Thank you! 3- Show intermediate steps of sorting the a.docxPlease explain- Thank you! 3- Show intermediate steps of sorting the a.docx
Please explain- Thank you! 3- Show intermediate steps of sorting the a.docx
 
Please explain why the answer is B instead of D 5- Which of the follow.docx
Please explain why the answer is B instead of D 5- Which of the follow.docxPlease explain why the answer is B instead of D 5- Which of the follow.docx
Please explain why the answer is B instead of D 5- Which of the follow.docx
 
Please Drawing this numbers using python Draw these follow.docx
Please Drawing this numbers using python             Draw these follow.docxPlease Drawing this numbers using python             Draw these follow.docx
Please Drawing this numbers using python Draw these follow.docx
 
PLEASE don't copy and paste from a previous answer because it was inco.docx
PLEASE don't copy and paste from a previous answer because it was inco.docxPLEASE don't copy and paste from a previous answer because it was inco.docx
PLEASE don't copy and paste from a previous answer because it was inco.docx
 
Please draw concept map Cdc45 Cdc6 Cdt1 Clamp Clamp loader CMG comp.docx
Please draw concept map    Cdc45 Cdc6 Cdt1 Clamp Clamp loader CMG comp.docxPlease draw concept map    Cdc45 Cdc6 Cdt1 Clamp Clamp loader CMG comp.docx
Please draw concept map Cdc45 Cdc6 Cdt1 Clamp Clamp loader CMG comp.docx
 
Please dont copy paste a-What is customer service- b- Main theories o.docx
Please dont copy paste a-What is customer service-  b- Main theories o.docxPlease dont copy paste a-What is customer service-  b- Main theories o.docx
Please dont copy paste a-What is customer service- b- Main theories o.docx
 
PLEASE DONT COPY ANSWER Draw a DFA that accepts the strings that repre.docx
PLEASE DONT COPY ANSWER Draw a DFA that accepts the strings that repre.docxPLEASE DONT COPY ANSWER Draw a DFA that accepts the strings that repre.docx
PLEASE DONT COPY ANSWER Draw a DFA that accepts the strings that repre.docx
 
Please do this for me!! I would gladly appreciate it- Write one result.docx
Please do this for me!! I would gladly appreciate it- Write one result.docxPlease do this for me!! I would gladly appreciate it- Write one result.docx
Please do this for me!! I would gladly appreciate it- Write one result.docx
 
Please copy and paste the code and explain why it won't work- It is su.docx
Please copy and paste the code and explain why it won't work- It is su.docxPlease copy and paste the code and explain why it won't work- It is su.docx
Please copy and paste the code and explain why it won't work- It is su.docx
 
Please complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docxPlease complete all the code as per instructions in Java programming.docx
Please complete all the code as per instructions in Java programming.docx
 
please ask and answer questions in internet technologies in the follo.docx
please ask and answer questions in  internet technologies in the follo.docxplease ask and answer questions in  internet technologies in the follo.docx
please ask and answer questions in internet technologies in the follo.docx
 
Please answer the multiple choice questions with detailed explanation.docx
Please answer the multiple choice questions with detailed explanation.docxPlease answer the multiple choice questions with detailed explanation.docx
Please answer the multiple choice questions with detailed explanation.docx
 
Please answer the following questions about the network of streets in.docx
Please answer the following questions about the network of streets in.docxPlease answer the following questions about the network of streets in.docx
Please answer the following questions about the network of streets in.docx
 
Please answer 16-29- thank you P4- Dissection of the Fetal Pig Ventr.docx
Please answer 16-29- thank you   P4- Dissection of the Fetal Pig Ventr.docxPlease answer 16-29- thank you   P4- Dissection of the Fetal Pig Ventr.docx
Please answer 16-29- thank you P4- Dissection of the Fetal Pig Ventr.docx
 
Please answer the 3 questions- Case Study 2 Too Much Fatigue and Stres.docx
Please answer the 3 questions- Case Study 2 Too Much Fatigue and Stres.docxPlease answer the 3 questions- Case Study 2 Too Much Fatigue and Stres.docx
Please answer the 3 questions- Case Study 2 Too Much Fatigue and Stres.docx
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docx
 

Recently uploaded

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportAvinash Rai
 
Accounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfAccounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfYibeltalNibretu
 
NLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxNLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxssuserbdd3e8
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...Nguyen Thanh Tu Collection
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPCeline George
 
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.pptxJosvitaDsouza2
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfVivekanand Anglo Vedic Academy
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsCol Mukteshwar Prasad
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasiemaillard
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...Sayali Powar
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...Nguyen Thanh Tu Collection
 
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.pdfCarlosHernanMontoyab2
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxRaedMohamed3
 
plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsparmarsneha2
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345beazzy04
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chipsGeoBlogs
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfTamralipta Mahavidyalaya
 

Recently uploaded (20)

Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
 
Accounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfAccounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdf
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
NLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxNLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptx
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
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
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
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
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
plant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated cropsplant breeding methods in asexually or clonally propagated crops
plant breeding methods in asexually or clonally propagated crops
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 

Please code in C language- Please do part 1 and 2- Do not recycle answ.docx

  • 1. Please code in C language. Please do part 1 and 2. Do not recycle answers and implement the starter code Starter code: #include <stdio.h> #include <ctype.h> #include <stdlib.h> #include <string.h> #include "linkedlist.h" // print an error message by an error number, and return // the function does not exit from the program // the function does not return a value void error_message(enum ErrorNumber errno) { char *messages[] = { "OK", "Memory allocaton failed.", "Deleting a node is not supported.", "The number is not on the list.", "Sorting is not supported.", "Reversing is not supported.", "Token is too long.", "A number should be specified after character d, a, or p.", "Token is not recognized.", "Invalid error number."}; if (errno < 0 || errno > ERR_END)
  • 2. errno = ERR_END; printf("linkedlist: %sn", messages[errno]); } node *new_node(int v) { node *p = malloc(sizeof(node)); // Allocate memory if (p == NULL) { error_message(ERR_NOMEM); exit(-1); } // Set the value in the node. p->v = v; // you could do (*p).v p->next = NULL; return p; // return } node *prepend(node *head, node *newnode) { newnode->next = head; return newnode; } node *find_node(node *head, int v) { while (head != NULL) { if (head->v == v) return head; head = head->next;
  • 3. } return head; } node *find_last(node *head) { if (head != NULL) { while (head->next != NULL) head = head->next; } return head; } node *append(node *head, node *newnode) { node *p = find_last(head); newnode->next = NULL; if (p == NULL) return newnode; p->next = newnode; return head; } node *delete_list(node *head) { while (head != NULL) { node *p = head->next; free(head); head = p;
  • 4. } return head; } void print_list(node *head) { printf("["); while (head) { printf("%d, ", head->v); head = head->next; } printf("]n"); } void print_node(node *p) { printf("%p: v=%-5d next=%pn", p, p->v, p->next); } void print_list_details(node *head) { while (head) { print_node(head); head = head->next; } } // functions that have not been implemented node *delete_node(node *head, int v) { // TODO
  • 5. error_message(ERR_NODELETE); return head; } /* * Given a pointer to the head node of an acyclic list, change the * next links such that the nodes are linked in reverse order. * Allocating new nodes or copying values from one node to another * is not allowed, but you may use additional pointer variables. * Return value is a pointer to the new head node. */ node *reverse_list(node *head) { // TODO error_message(ERR_NOREVERSE); return head; } Part 1. Delete node. The linked list example we have studied in lecture maintains a singly linked list of integers. The program can append and prepend integers to the list. Type help in the program to see a list of commands. Note that if the number to be added is already on the list, the program prints the information about the node that stores the number and does not add the number twice. The list is displayed every time an integer is processed. Currently, the program does not support the delete function. Complete the function delete.node() in linkedlist. c so that the program can delete an integer from the list. The prototype of the function is: [ text { node } * text { delete_node(node } * text { head, int v); } ] head is a pointer to the head node and v is the integer to be removed. The function returns the pointer to the head node of the new list, which could be the same as head. If v is not on the list, the function prints a message using the following function call: error_message(ERR_NOTFOUND). Below is an example session using the delete feature. $ ./1inkedlist-main 123456789 [ 1 , [ 1 , 2 , [ 1 , 2 , 3 , [ 1 , 2 , 3 , 4 , [ 1 , 2 , 3 , 4 , 5 , [ 1 , 2 , 3 , 4 , 5 , 6 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , d5 [ 1 , 2 , 3 , 4 , 6 , 7 , 8 , 9 , d3 [ 1 , 2 , 4 , 6 , 7 , 8 , 9 , d3 linkedlist: The number is not on the list. [ 1 , 2 , 4 , 6 , 7 , 8 , 9 , Part 2. List reversal. In this exercise, we implement another function reverse_list () in linkedlist. The prototype of the function is: [ text { node } * text {
  • 6. reverse_list (node } * text { head); } ] The function receives head as its sole argument, a pointer to the head node of the linked list. Assun the list is acyclic. The function must change the next fields of each node so that the nodes end up link in reverse order. The function must return the address of the new head node (originally last in the list You may use additional functions and local variables besides those already included in the starter code, b cannot change the values stored in the nodes or dynamically allocate new nodes. You can use either a lod or recursion. Below is an example session using the reversal feature. $./ linkedlist-main 1234556789 [ 1 , [ 1 , 2 , [ 1 , 2 , 3 , [ 1 , 2 , 3 , 4 , [ 1 , 2 , 3 , 4 , 5 , [ 1 , 2 , 3 , 4 , 5 , 6 ,