Hi.
I am working on this program for my C++ class. The assignment is you have to take a list, and sort it three different ways: Reverse, opposite order of how the user entered the numbers, Normal, how the user put in the numbers, and Sorted, from least to greatest.
Well, I got most of it done but when I compile it, I get an "implicit declaration of function "int swap(...)" According to the compiler, its on line 95. I have looked at this line and the declaration of my function "swap" but cannot find a problem with it. What does this type of error usually mean? Can anyone see what I am missing?
Thanks
Code:
#include<iostream.h>
int main()
{
//Funtion Prototypes
// The "s" variable stands for size
void normal(int norm_list[], int& s);
void reverse (int rev_list[], int& s);
void sort (int sort_list[], int& s);
void swap (int& x, int& y);
//Decleaer Variables
//Size is for the size of the list and index is the location in the array
int size, index;
//Ask user for size of the list
cout << "Please enter the size of the list: " ;
cin >> size;
//Decleare array list[]
//Also, for loop enters the list into the array
int list[size];
for (index=0; index <= size-1; index++)
{
cout << "Please enter the next interger: ";
cin >> list[index];
}
//Call to functions to sort the numbers
//Functions (in order): Reverse, Normal, Sort
reverse (list, size);
normal (list, size);
sort (list, size);
//Program End
cout << endl;
return 0;
}
//Reverse Function
void reverse (int rev_list[], int& s)
{
int x;
cout << "List in REVERSE order:\n\n";
for (x = s-1; x >=0; x--)
{
cout << rev_list[x] << "\n";
}
cout << "\n\n";
}
//Normal Function
void normal(int norm_list[], int& s)
{
int x;
cout << "List in NORMAL order (as user inputted it): \n\n";
for (x=0; x <= s-1; x++)
{
cout << norm_list[x] << "\n";
}
cout << "\n\n";
}
//Sort Function
void Sort(int sort_list[], int& s)
{
int pass, k, x;
for (pass=1; pass < s; pass++)
{
for (k=0; k < s - 1; k++)
{
if (sort_list[k+1] < sort_list[k])
{
swap (sort_list[k], sort_list[k+1]);
}
}
}
cout << "List in SORTED order (from least to greatest): \n\n";
for (x=0; x < s; x++)
{
cout << sort_list[x] << "\n";
}
cout << "\n\n";
}
//Swap Function
void swap(int& x, int& y)
{
int temp;
temp = x;
x = y;
y = temp;
}