program is to sort an array in ascending and descending order using selection sorting.
Here are some of my questions right now. I need a bit of guidance to continue on.
Output of run of program thus far only helps to see the original array (see bottom of post)
(1) do I need two separate functions to sort in ascending and descending order -- the original array is sorted twice
(2) do I need 3 parameters if I define number of elements of original array -- textbook explains that one int variable is the first element and the other int variable is the last element in array
(3) is the function find_largest_element to return a value or anything at all???
Code:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define NUMELEM 30
#define MAXELEM 200
void ascend_sort(int a[],int b, int e);
void descend_sort(int a[], int e, int b);
void random_array(int a[], int b);
void find_largest_element (int a[], int b, int e);
main()
{
int array[NUMELEM];
int first;
int last;
/* create array */
/* find largest element */
/* sort in ascending order using selection sorting */
/* sort in descending order using selection sorting */
/* print new arrays */
random_array(array,NUMELEM);
}
void find_largest_element(int a[], int b, int e)
{
}
void ascend_sort(int a[],int b, int e)
{
int largest;
int temp;
}
void descend_sort(int a[], int e, int b)
{
}
void random_array(int a[], int b)
{
int i;
for (i=0; i < NUMELEM; i++)
{
a[i] = rand()%MAXELEM+1;
printf("%3d ",a[i]);
if ((i+1)%10==0)
printf("\n");
}
}
gcc selecting.c
a.out
39 159 114 116 52 28 11 20 13 87
150 168 85 61 26 144 90 184 138 167
167 179 96 112 168 55 32 146 83 137