#include <iostream>
#include <conio>
int main()
{
cout<<swap_values(int &v1, int &v2);
getch();
return 0;
}
void swap_values(int &v1, int &v2)
{
int temp;
temp = v1;
v1=v2;
v2=temp;
}
int index_of_smallest(constint a[], int begin_index, int end_index)
{
int min = a[end_index], index_of_min = end_index;
for(int index=begin_index; index<end_index; index++)
if(a[index]<min)
{
min = a[index];
index_of_min = index;
}
return index_of_min;
}
void sort(int a[], int last_index)
{
int index_of_next_smallest;
for (int index=last_index; index>=0; index--)
{
index_of_next_smallest = index_of_smallest(a, 0, index);
swap_values(a[index], a[index_of_next_smallest]);
}
}
Hi, I got this code from C++ book, but then it's without line 1-9, so, I don't know how to write the code to call the function after line 9, can anyone help?
The question is something like implementation of a sorting algorithm that sorts a list of numbers in an array...TQ...
1. Declare the functions before their first use.
2. Call the functions by passing the values in.
Note line 6 won't work because swap_values() doesn't return a value for the cout. Also, don't use the & when calling the function. Also, you didn't define v1 or v2.