-
Ok so I fixed a few things and changed some of the variables that where written as two different things but should have been carried over as one. So JDGATX, your saying to get rid of the variable n?
here is the new code I think I have get_min_range right now Ill look at sort_arr
Code:
// Array.cpp : Defines the entry point for the console application.
//
#include<stdio.h>
#include<stdafx.h>
#include"conio.h"
#include<math.h>
#define x 10
int get_min_range(int arr[], int small, int last)
{
small=0;
for(last=1; last<x; ++last)
if (last<small)
arr[small]=arr[last];
return(small);
}
void sort_arr(int arr[], int n)
{
int small, temp=0, index_of_min;
for (small = 0; small < x-1; ++small)
index_of_min = get_min_range(arr, small, x-1);
if (small != index_of_min)
temp = arr[index_of_min];
arr[index_of_min] = arr[small];
arr[small] = temp;
}
int main()
{
int f=0, n=0, arr[x];
for(int n=0; n<x; n++)
{
printf("Enter a number in the array:");
scanf_s("%d", &arr[n]);
}
sort_arr( arr, n);
for(f=0; f<x; f++)
printf("%d", arr[f]);
getch();
return (0);
}
-
My problem is that it is only switching the first and last values if they are not in order.
-
There's still no point in passing in 'small' under your current implementation because you just set it to zero immediately upon entering the get_min_range function.
-
You still have the same problem in your sort_arr function that you did the LAST time I commented on it. Since this:
...is outside your for loop, small will always be x-1 when that statement executes, meaning you will always swap the last position, no matter what.
-
Thanks guys for the help I got a friend who is good at this he helped me too but thanks for all the suggestions they really helped.
-
Hi All,
3wit, please post the final code, so we all can learn from it. Cheers.
coolboarderguy