C ++无法弄清楚我的函数调用有什么问题

时间:2017-06-23 06:36:58

标签: c++

我正在尝试进行选择排序,但由于某种原因我每次都运行我的代码,我的编译器给了我从int到int的无效转换错误。这是我的代码

#include <iostream>
#include <fstream> 
#include <cstdlib>

using namespace std;

selectionSort (int[], int);

int main()
{
   fstream theFile("test.txt");
   const int ARRAY_SIZE = 12; // Array size
   int numbers[ARRAY_SIZE];
   int counter = 0;
   int linecount = 0;         // Loop counter variable
   int finalArray;

   while (counter < ARRAY_SIZE && theFile >> numbers[counter])
   {

       counter++;
   }

   theFile.close();
   // Display the numbers read:
   cout << "The array entered by user: ";
   for (counter = 0; counter < ARRAY_SIZE; counter++)
   {
       finalArray = numbers[counter];
       cout << finalArray << " ";
   }

  selectionSort(finalArray, ARRAY_SIZE);

  cout << endl;


  return 0;
}

void selectionSort(int UnsortedArray[], int SizeofArray)
{
    for (int i = 0; i< SizeofArray; i++)
    {
        int smallest = UnsortedArray[i];
        int smallestIndex = i;

        for(int m = i; m < SizeofArray; m++)
        {
            if(UnsortedArray[m] < smallest)
            {
                smallest = UnsortedArray[m];
                smallestIndex = m;
            }

        }
        swap(UnsortedArray[i], UnsortedArray[smallestIndex]);
    }

}

对不起,如果我有很多错误,我只是一个初学者。

0 个答案:

没有答案