181: find the largest element in the linked list

PHOTO EMBED

Tue May 23 2023 15:39:15 GMT+0000 (Coordinated Universal Time)

Saved by @saakshi #c++

//MIN_INT= -32768

//iterative function
max(Node *p){
  int m= INT32_MIN;
  while(p){
    if(p->data > m)
      m=p->data;
    p=p->next;
  }
  return m;
}

//recursive function
max(Node *p){
  int x=0;
  if(p==0)
    return INT32_MIN;
  else
    x= max(p->next);
  
  if(x>p->data)
  	return x;
  else
    return p->data;
}
content_copyCOPY