Shellsort vector

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
      static void 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;
                else if (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!
Topic archived. No new replies allowed.