I do not understand pointers and especially not linked lists. If someone could e
ID: 3599438 • Letter: I
Question
I do not understand pointers and especially not linked lists. If someone could explain the code and break it down in the solution I'd appreciate it.
Part l: Write and Test C code/program Suppose the following struct and variable declarations for linked list with pointer, where the linked list is ordered by the ABC123 ID. Each node is represented by the following Node definition typedef struct char szAbc123Id [7]; double dGPA; } Student; typedef struct Node Student student; // This is different from last week since // student is in the node instead of // directly containing szAbc123Id and dGpa. struct Node *pNext; } Node; Node *pHead; Node *pFind, *pWorst, *pPrecedes; Create a linked list with the following 5 elements "apg238" 3.76 "byi761" 3.21 "ijx218" 3.52 "jnv088" 3.11 uyx181"z pHead 3.85 Implement and test the following functions void printHighGPA (Node *pHead), which prints the ABC123 ID and GPA for students having a GPA >= 3.5 of students in the linked list that begins at pHead . Node *searchLL (Node *pHead, const char szMatchId[], Node **ppPrecedes) that uses the ABC123 ID and find the specified student in the linked list. If it is found, return the pointer to the node containing that ID. If it is not found, return NULL. Also, return (via the parameter list) the pointer to the node that precedes that node. If there isn't a preceding node, this should be NULL Node *getWorststudent(Node *pHead), which is passed the pointer to a linked list. It returns a pointer to the node for the student with the lowest GPA. Return NULL if there aren't any nodes in the linked listExplanation / Answer
In this Code:
Student is a Abstract Data Type containing a Character array of size 7 (may be used for storing string of max length 6) and a double data dGPA
Node is another Abstract Data Type containing a Student data and a pointer that can store the address of next Node.
a)
void printHighGPA(Node *pHead) {
while(pHead != NULL) { //while head does not point the end of the list
if (pHead ->student.dGPA > 3.5) //note the use of "->" in pHead ->student because pHead is a pointer to ADT Node. note the use of "."(dot) in student.dGpa because student is not a pointer to ADT but the variable itself.
printf("%s ", pHead ->student.szAbc123Id);
pHead = pHead->pNext;
}
}
b
Node *searchAll(Node *pHead, const char szMatchId[], Node **ppPreceedes) {
Node *prev = NULL;
while (pHead != NULL) {
if (strcmp(pHead->student->szAbc123Id, szMatchId) == 0) {
return pHead;
*ppPreceedes = prev;
}
prev = pHead;
pHead = pHead -> pNext;
}
return NULL;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.