- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
void dualSort(int [], double [], int);
int main()
{
const int ARRAY_SIZE = 1000; // Array size
double accountNumbers[ARRAY_SIZE]; // Array with 1000 elements
double accountBalances[ARRAY_SIZE]; // Loop counter variable
int count = 0; // Input file stream object
ifstream inputFile;
// Open the file.
inputFile.open("FinalNumbers.txt");
// Read the numbers from the file into the array
while (count < ARRAY_SIZE && inputFile >> accountNumbers[count] >> accountBalances[count] ) {
count++;
}
inputFile.close();
// Display the read data
cout << "The bank account numbers are: " << endl;
for (int count = 0; count < ARRAY_SIZE; count++) {
cout << accountNumbers[count] << "\n" << accountBalances[count] << " " << endl;
}
void dualSort(int accountNumbers[], double accountBalances, int ARRAY_SIZE);
}
我需要使用选择排序或冒泡排序算法。
我有Bank Account Numbers,必须与那里的Account Balance进行相应的升序排序,所有数据都是从文件中读取的。
排序数据后,我必须将其重写到另一个文件中,这是我最不担心的。
所以问题是我如何按升序对我的 accountNumbers
以及紧随其后的 accountBalance
进行排序。
最佳答案
您需要根据 accountNumbers
进行排序,但将每个交换操作应用于两个数组。
下面是使用选择排序的代码:
void dualSort(int accountNumbers[], double accountBalances[], int ARRAY_SIZE)
{
int minIndex;
for(int i = 0; i < ARRAY_SIZE - 1; i++)
{
minIndex = i;
for(int j = i + 1; j < ARRAY_SIZE; j++)
{
if(accountNumbers[j] < accountNumbers[minIndex])
{
minIndex = j;
}
}
swap(accountNumbers[i], accountNumbers[minIndex]);
swap(accountBalances[i], accountBalances[minIndex]);
}
}
关于c++ - 双重选择对数组进行排序 - honeSTLy stumped,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43773721/
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
void dualSort(int [], double [], int); int main() { const int ARRAY_SIZE = 1000; // A
所以这是我看到这段代码的作用: 制作了一个数组 一个循环迭代10次 创建了一个新数组 对这个新数组的引用保存在第一个数组中 10 个数组现在位于原始数组中,值为 0、1、2、3... 真正发生的事情:
我使用的是 Hibernate 4.1,每当我尝试存储已添加到对象集合中的临时标记列表时,我都会收到以下异常。 org.hibernate.TransientObjectException: obje
我正在阅读有关 Swing Timers 的文章,该示例看起来与我尝试做的完全不同,因此我发现将其应用于我的程序在逻辑上令人困惑。 我开始觉得我什至不需要计时器。 这是我正在尝试做的事情: 我正在制作
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 7 年前。 Improve this qu
我是一名优秀的程序员,十分优秀!