//List: ptr to a linked list of Node (each with int data, and Node * next) //Ret
ID: 3868777 • Letter: #
Question
//List: ptr to a linked list of Node (each with int data, and Node * next) //Return a pointer to node with the largest value. //You may assume list has at least one element //If more than one element has largest value, //break tie by returning a pointer to the one the occurs //earlier in the list, i.e. closer to the head Node * pointerToMax(Linkedl_ist *list) { //Code may assume that these assertions are true: //so does not need to do error checking for these conditions. assert(list!=NULL): assert(list rightarrow head !=NULL): //TODO: Insert code here to calculate and return //value of pointer to max element (first one if ties.)Explanation / Answer
max=0;
Node *n;
while(list!=NULL){
if(list->data>max){
max=list->data;
*n=list
}
list=list->next;
}
return n; // or *n,whatever u need
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.