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

PPTX
singlelinkedlistasdfghzxcvbnmqwertyuiopa
PPTX
Linked list data structures and algorithms
PPTX
Implemention of Linked list concept in Data Structures
PDF
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
PPTX
1.3 Linked List.pptx
PPTX
LinkedList-VJ-V2.pptx Analysis of Algorithms and Data Structures
PDF
Singly linked list
PDF
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
singlelinkedlistasdfghzxcvbnmqwertyuiopa
Linked list data structures and algorithms
Implemention of Linked list concept in Data Structures
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
1.3 Linked List.pptx
LinkedList-VJ-V2.pptx Analysis of Algorithms and Data Structures
Singly linked list
Create a link list. Add some nodes to it, search and delete nodes fro.pdf

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

PPTX
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
PDF
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
PPTX
Data Structures - Lecture 7 [Linked List]
PDF
TutorialII_Updated____niceupdateprogram.pdf
DOC
Final ds record
PPTX
Data Structures and Agorithm: DS 04 Linked List.pptx
PDF
QUESTION If you look at the code, youll see that we keep two list.pdf
PDF
1) Create a function called reverselist that will take a simple list.pdf
DOCX
DS UNIT4_OTHER LIST STRUCTURES.docx
DOCX
Bsf23006565 dsa 3rd assignment.docx............
PPT
linkedlistwith animations.ppt
PPT
Algo>ADT list & linked list
PPT
Operations on linked list
PPTX
Unit II Data Structure 2hr topic - List - Operations.pptx
PDF
Seo Expert course in Pakistan
PPTX
Linked lists
PPT
Mi 103 linked list
PPT
17 linkedlist (1)
PDF
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdf
PPTX
Engineering.CSE.DataStructure.Linkedlist.notes
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
C++ Doubly-Linked ListsThe goal of the exercise is to implement a.pdf
Data Structures - Lecture 7 [Linked List]
TutorialII_Updated____niceupdateprogram.pdf
Final ds record
Data Structures and Agorithm: DS 04 Linked List.pptx
QUESTION If you look at the code, youll see that we keep two list.pdf
1) Create a function called reverselist that will take a simple list.pdf
DS UNIT4_OTHER LIST STRUCTURES.docx
Bsf23006565 dsa 3rd assignment.docx............
linkedlistwith animations.ppt
Algo>ADT list & linked list
Operations on linked list
Unit II Data Structure 2hr topic - List - Operations.pptx
Seo Expert course in Pakistan
Linked lists
Mi 103 linked list
17 linkedlist (1)
I will provide my LinkedList from my last lab.LinkedList.cpp~~~~.pdf
Engineering.CSE.DataStructure.Linkedlist.notes
Ad

More from cgraciela1 (20)

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

Recently uploaded (20)

PDF
What if we spent less time fighting change, and more time building what’s rig...
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PPTX
Introduction to Building Materials
PPTX
Cell Types and Its function , kingdom of life
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Trump Administration's workforce development strategy
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
Indian roads congress 037 - 2012 Flexible pavement
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Classroom Observation Tools for Teachers
PPTX
Final Presentation General Medicine 03-08-2024.pptx
What if we spent less time fighting change, and more time building what’s rig...
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
Introduction to Building Materials
Cell Types and Its function , kingdom of life
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Trump Administration's workforce development strategy
Final Presentation General Medicine 03-08-2024.pptx
Chinmaya Tiranga quiz Grand Finale.pdf
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Indian roads congress 037 - 2012 Flexible pavement
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
RMMM.pdf make it easy to upload and study
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
202450812 BayCHI UCSC-SV 20250812 v17.pptx
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Classroom Observation Tools for Teachers
Final Presentation General Medicine 03-08-2024.pptx

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 ,