排序程序的错误代码
Error code with sorting program
我目前正在尝试编写一个按字符串字母顺序排列的程序。我有一个错误。minLocation不接受2个参数。我对编程还很陌生,有人能告诉我为什么我的这部分代码是错误的吗?
int minLocation(string list[], int first, int last)
{
int mIndex=first;
int loc = 0;
for (loc = first+1; loc <= last; loc++)
if (list[loc] < list [mIndex])
mIndex = loc;
return mIndex;
void Sort(string slist[],int length)
{
int mIndex;
for (int loc = 0; loc < length-1; loc++)
{
mIndex = minLocation (loc,length-1);
swap (loc, minIndex);
}
}
如果没有看到minLocation
的定义,我们就无法判断。但可以肯定的是,它不需要两个论点——编译器不会为了好玩而对你撒谎,你通常可以假设他们说的是真的:-)
你需要找到定义,比如:
int minLocation (int loc) { ...
并弄清楚实际上是如何调用它的。考虑到它似乎在试图找出两个索引中哪一个的值更低,它可能需要比两个参数更多的。
除此之外,您还需要决定是想要名为mIndex
还是minIndex
的变量。大多数编译器都不够聪明,无法为您解决这个问题。
根据您的编辑,muinFunction
定义为:
int minLocation (string list[], int first, int last) { ...
很明显,它还需要字符串数组以及两个索引。您需要将呼叫更改为:
mIndex = minLocation (slist, loc, length-1);
并密切关注swap
呼叫。根据编码风格,它可能有类似的要求。
相关文章:
- 错误处理.将系统错误代码映射到泛型
- 为什么我在使用void函数时得到错误代码C2276
- 尝试链接我的着色器时,我收到错误代码"error c5145 must write to gl_position"
- 逻辑运算符上出现错误代码 a')'
- 'val' Arduino 错误代码之前的预期'('
- 我在贪吃蛇游戏中收到了错误代码 -1073741571
- 当我选择大于 720 的矩阵大小时,程序退出并显示错误代码.可能是什么原因?
- 排序程序的意外错误代码
- 在计算机级别,应用程序以二进制方式运行,然后当发生运行时错误时,它如何呈现回错误代码
- 当我尝试构建和运行C 程序时,获取Xcode错误代码
- 可视化如何使用C++程序获取DHCPV6服务器IP.我尝试使用DHCPv6RequestParams,但总是收到错误代码
- 如果应用程序从安装选项启动,则加载库失败,错误代码为 126
- 使用Outlook 2016:MAPISendMail在Windows应用程序中失败,并返回"MAPI_E_FAILURE"作为错误代码
- Opencv应用程序在运行时崩溃,错误代码为0x0000142
- 错误代码 C2451 无法运行基本程序
- 程序超过了时间限制,这似乎是不可能的——错误代码
- 通过C++程序中EOF(CTRL+D)字符上的错误代码提供用户反馈
- 排序程序的错误代码
- C++应用程序退出错误代码62097-这意味着什么
- 程序中"error: stray '302'"编译错误 代码::块