staticvoid shellSort(vector<int> numbers, int array_size)
{
int i, j, increment, temp;
increment = 3;
while (increment > 0)
{
for (i = 0; i < array_size; i++)
{
j = i;
temp = numbers[i];
while ((j >= increment) && (numbers[j - increment] > temp))
{
numbers[j] = numbers[j - increment];
j = j - increment;
}
numbers[j] = temp;
}
if (increment / 2 != 0)
increment = increment / 2;
elseif (increment == 1)
increment = 0;
else
increment = 1;
}
}
int main()
{
string file1;
vector<int> shell_first;
int count1 = 0;
int data1;
//Asks user to enter in the file----------------------------------------
cout << "\nPlease enter in the address of the first data file that you want to open: " << endl;
getline(cin, file1);
ifstream textFile1 (file1);
//Tests the file
if (textFile1.fail())
{
cout << "File was not found"<< endl;
system("PAUSE");
exit (1);
}
else
cout << "File opened successfully" << endl;
do
{
textFile1 >> data1;
shell_first.push_back(data1);
count1++;
}while(!textFile1.eof());
shellSort(shell_first, count1);
cout << "\Contents of shell: ";
for(int i = 0; i < count1; i++)
{
cout << shell_first[i] << endl;
}
cout << ""<< endl;
system("PAUSE");
return 0;
This is me attempting to have a vector work with the shellsort function. I have used an array with it and it works fine, but when I use a vector it doesn't work. The reason I am using a vector is because I don't know the size of the inputted file.
Anywhoooo, if I could get some help making this vector work with the shellsort, I would greatly appreciate it. Thanks!