Here is my code:
Expand|Select|Wrap|Line Numbers
- #include <iostream>
- using namespace std;
- int n;
- int a[6];
- int main()
- {
- int i;
- cout << "How many elements do you want in the array?\nNote: It must be less than or equal to five and greater than 0. ";
- cin >> n;
- cout << endl;
- if((n > 5) || (n < 1))
- {
- cerr << "The size of the array is not valid!\n\n";
- return 0;
- }
- for(i = 1; i <= n; i++)
- {
- cout << "Enter a number to put in the array: ";
- cin >> a[i];
- }
- cout << "\nOriginal array: ";
- for(i = 1; i <= n; i++)
- cout << a[i] << " ";
- void sort(int n, int a[]);
- cout << "\nSorted array: ";
- for(i = 1; i <= n; i++)
- cout << a[i] << " ";
- cout << endl;
- return 0;
- }
- void sort(int n, int a[])
- {
- int j;
- cout << "sort test before call to move\n";
- for(j = 1; j <= n-1; j++)
- {
- if(a[j] > a[j+1])
- int move(int a[], int j);
- }
- cout << "sort test after call to move\n";
- return;
- }
- int move(int a[], int j)
- {
- int k;
- int temp = a[j+1];
- a[j+1] = a[j];
- cout << "move test before call to findkay\n";
- int Findkay(int k, int j, int a[], int temp);
- cout << "move test after call to findkay\n";
- a[k] = temp;
- return k;
- }
- int Findkay(int k, int j, int a[], int temp)
- {
- k = j;
- int sw = 0;
- while((k > 1) && (sw = 0))
- {
- if(a[k-1] > temp)
- {
- a[k] = a[k-1];
- k = k-1;
- }
- else
- sw = 1;
- }
- cout << "findkay test\n";
- return k;
- }