I have to create a C++ program that has one main function and one void function. "sortof" must be the void function's name. the void function has 2 arguements, which are both 1-D arrays of length 4. the main program asks the user for 4 different numbers. these are stored in one of the arrays. the function is then called and it sorts the numbers form smallest to biggest in the second array. the main program then prints both the input array and the sorted array to the screen. As far as sorting goes, i'm lost. it says i'm supposed to just determine the max, the nin and then do the same for the two left behind. HELP PLEASE!!!
Urgent C++ array sorting question?
I have a quicksort function on my website. It is easy and can be implemented in your code
iamtruancy.co.nr
Navigate to c++, click the link "median" or "mode"
void ord(int size){
int i, j;
//test original number against all
for (i = 0; i %26lt; size; i++){
for (j = i + 1; j %26lt;= size; j++){
//arr is your array
//if new number is bigger than swap them
if ( arr[j] %26gt; arr[i] )
swap(arr[j], arr[i]);}
//show array
cout %26lt;%26lt; endl %26lt;%26lt; arr[i]; }}
Reply:I do not under stand where you are stuck at. Did you get the arrays to work? Or are you stuck on that? If you need any help go on google and search for "C++ Array Functions" and you should get some help.
Reply:void sortof(double f[], double s[] ,int size)//u need to pass size also
{
int temp;
//copy the original array
for(int i=0;i%26lt;size;i++)
s[i]=f[i];
for(int i=0;i%26lt;size-1;i++)
{
if(s[i]%26gt;s[i+1])
{
temp=s[i];
s[i]=s[i+1];
s[i+1]=temp;
}
}
}
thats it
after calling sort of function
display min=s[0]
max=s[size-1]
that s all
Reply:sounds like you need to implement a sorting function, unless you can use the standard qsort method in C.
google "quick sort" and "insertion sort" to get started on that.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment