首页 > 解决方案 > 递归查找出现次数

问题描述

我需要编写一个函数来查找文本中最常见的起始字母。文本由空格解析,所有单词都使用按字典顺序排序的链表链接。我写了一个函数来查找起始字母的出现次数,现在需要编写一个递归函数来返回最常见的字母。

这是出现次数的函数:

public int howManyStarting (char letter) {
    int counter=0;
    WordNode current= _head;
    while (current != null){
        if (current.getWord().charAt(0) == letter){
            counter += current.getNumOfAppearance();
        }
        current = current.getNext();
    }
    return counter;

标签: javarecursion

解决方案


推荐阅读