Im new to C. Say if
struct test{
int val;
struct test *next
};
If a list has been created using this struct, how do you find the maximum value via pointers?
Assuming list is filled with objects of the above struct, I have tried
struct test *t1 = malloc(sizeof (struct test));
struct test *t2 = malloc(sizeof (struct test));
While (list !=NULL){
int max=0;
struct test *t1, *t2;
if(t1->val < t2->val){
max = t2->val;
}
list = list->next;
}
But I guess I dont understand the logic behind it. I just need an explanation or an example on how to find the maximum value of a list of structs using pointers. Your help will be appreciated.
This may help you out understanding (I guess)
snippet:
EDIT: assuming t1 refers to a populated list.