If you attempt to implement both functions, you will only receive credit for the
ID: 3683423 • Letter: I
Question
If you attempt to implement both functions, you will only receive credit for the first one that you implement. Assume you have been provided the following structure definition and typedefs: struct node { int data; struct node * nextPtr;}; typedef struct node Node; typedef struct node * NodePtr; Write a function to print the items in a linked list in reverse. For example, if your linked list contains nodes with data members 4, 7, 8, and 10, your function should print 10 8 7 4. void printInReverse(NodePtr startPtr); Write a function to delete the first node from a linked list of integers and return the deleted node's data value. You may assume the list is non-empty. The prototype for this function appears below: int popFirstNode(NodePtr *startPtr);Explanation / Answer
#include struct node { int data; struct node* next; }; void ReversePrint(struct node* head) { if(head == NULL) return; ReversePrint(head->next); printf("%d ", head->data); } int main() { struct node first; struct node second; struct node third; first.data = 1; second.data = 2; third.data = 3; first.next = &second; second.next = &third; ReversePrint(&first); // Should print: 3 2 1 printf(" "); return 0; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.