小编Sh0*_*gun的帖子

C++帮助在地图中查找最大值

我一直在做基本程序来找到矢量的最大值,最小值,中值,方差,模式等.一切都很顺利,直到我进入模式.

我看到它的方式,我应该能够循环遍历向量,对于每个出现的数字,我在地图上增加一个键.找到具有最高值的密钥将是发生最多的密钥.与其他键相比,它会告诉我它是单个多重模式还是无模式答案.

这是导致我如此麻烦的代码块.

map<int,unsigned> frequencyCount;
// This is my attempt to increment the values
// of the map everytime one of the same numebers 
for(size_t i = 0; i < v.size(); ++i)
    frequencyCount[v[i]]++;

unsigned currentMax = 0;
unsigned checked = 0;
unsigned maax = 0;
for(auto it = frequencyCount.cbegin(); it != frequencyCount.cend(); ++it )
    //checked = it->second;
    if (it ->second > currentMax)
    {
        maax = it->first;
    }
    //if(it ->second > currentMax){
    //v = it->first

cout << " The highest value …
Run Code Online (Sandbox Code Playgroud)

c++ dictionary vector mode max

38
推荐指数
5
解决办法
6万
查看次数

初始化自定义类型的数组

所以我正在搞乱无意识和多态性.一切都很顺利,直到我到达测试人员,我必须做一个类型员工(我的超级班)的数组.目前尝试运行此程序给我这个错误.

线程"main"java.lang.NullPointerException中的异常

我假设这与我声明我有employeeArray = null;时有关.但是把它留下来我把每个员工都放到数组中会出错,它说必须启动员工数组,默认情况下通过包含employeeArray = null;来实现.我在java上的这本书并没有真正触及这些类型的数组,而且我一直无法在网上找到麻烦的答案.任何人都可以提供任何帮助将不胜感激.

我也试过这样的事

Employee [] employeeArray = new Employee[3] ;
Run Code Online (Sandbox Code Playgroud)

这没有返回任何错误,但没有返回我正在寻找的东西.这更像我的需要,但我的超级和子类有问题吗?

public class EmployeeTest {

public static void main(String[] args){

Employee [] employeeArray = null;
SalariedEmployee employee1 = new SalariedEmployee("Esther", "Smith", "111-111-111", 6, 2011, 2400); 
CommissionedEmployee employee2 = new CommissionedEmployee("Nick", "McRae", "222-222-222", 1, 1998, 50000, 0.1);
SalPlusCommEmployee employee3 = new SalPlusCommEmployee("Dan", "Mills", "333-333-333", 3, 2011, 1000, 0.05, 500 );

employeeArray[0] = employee1;
employeeArray[1] = employee2;
employeeArray[2] = employee3;

System.out.println(employeeArray[0].getEmployeeDetails);

System.out.println(employee1.toString()); // call the method from …
Run Code Online (Sandbox Code Playgroud)

java arrays inheritance initialization

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

arrays ×1

c++ ×1

dictionary ×1

inheritance ×1

initialization ×1

java ×1

max ×1

mode ×1

vector ×1