List 查找最大元素低于列表中的平均值

List 查找最大元素低于列表中的平均值,list,max,average,doubly-linked-list,List,Max,Average,Doubly Linked List,我想找到比所有元素的平均值低的最大元素。不难找到max元素: int max (node *p) { int current = p->data; int next; if (p->next == NULL) //The value at this node is obviously larger than a non-existent value { return current; } else

我想找到比所有元素的平均值低的最大元素。不难找到max元素:

int max (node *p) 
{
    int current = p->data;
    int next;
    if (p->next == NULL)   //The value at this node is obviously larger than a non-existent value 
    {    
        return current;
    } 
    else 
    {        
        next = max(p->next); //Recur to find the highest value from the rest of the LinkedList
    }
    if(current > next)        //Return the highest value between this node and the end of the list 
    {
        return current;
    } 
    else 
    {
        return next;
    }
}

但是要从所有的平均值中找到最大值对我来说有点难。是的,我可以做一些其他的函数来处理列表的大小和平均值,但是有可能在一个函数中完成所有这些吗。一切帮助都将不胜感激。提前感谢您的时间。

最简单的方法是分两步完成:

首先,编写一个函数来计算整个列表的平均值, 然后使用稍加修改的max函数查找给定阈值以下的最大值, 结合两者 利润
在一个函数中可以实现所有这些,你是说在数组中一次通过就可以实现,还是说在同一个长函数中就可以实现?起初我是说在字面上可以实现,但现在我想在一次通过中实现。。。但是这两种方法都很好。好的,我找到了列表的平均值,但是我在修改max函数时遇到了一些问题,因此如果元素