1. ## selection sorting

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

2. Your best bet would be to use a linked list. That way it is easy to sort it and add at will. This seems to be the best way for your problem.

3. ## can't use linked lists

know recursion
know array/pointers (so-so)

4. Oh. Let me think. I'll get back to you later.

5. ## finding largest element of array

I am working on the function largest_element that seeks to find largest element of array. Now I am not sure if I set it up correctly to find the largest element. And also, I am not sure if call it correctly, (or have understandable arguments).

[CODE]

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

#define NUMELEM 30
#define MAXELEM 200

void ascend_sort(int a[],int n);
void descend_sort(int a[], int n);
void random_array(int a[], int n);
int largest_element (int a[], int f, int l);

main()
{
int array[NUMELEM];
int last=0;

/* 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);

/* need to call function largest_element to use later */

last=largest_element(array,array[0],array[NUMELEM-1]);

printf("%d",last);
}

/* FUNCTION: largest_element : my resource text says to */
/* make i and j point to the first element of array (but it */
/* does not assume a[0] is the first element for some */
/* reason; f and l are representing first and last elements */
/* of array passed */

int largest_element(int a[], int f, int l)
{
int i=f;
int j=f;

do {
i++;
if (a[i] > a[j]) {
j=i;
}
} while (i != l);

return j;
}

void ascend_sort(int a[],int n)

{
int largest;
int temp;

}

void descend_sort(int a[], int n)
{

}

void random_array(int a[], int n)
{
int i;

for (i=0; i < NUMELEM ; i++)

{
a[i] = rand()%MAXELEM+1;
printf("%3d ",a[i]);

if ((i+1)%10==0)
printf("\n");
}
}

6. ## last post messed up

REPOST

I am working on the function largest_element that seeks to find largest element of array. Now I am not sure if I set it up correctly to find the largest element. And also, I am not sure if I call it correctly, (or have understandable arguments). Something is not
correct because when I run it, I am not getting the right value for last (which is variable returned from function largest_element).

Code:
```

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

#define NUMELEM 30
#define MAXELEM 200

void ascend_sort(int a[],int n);
void descend_sort(int a[], int n);
void random_array(int a[], int n);
int largest_element (int a[], int f, int l);

main()
{
int array[NUMELEM];
int last=0;

/* 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);

/* need to call function largest_element to use later */

last=largest_element(array,array[0],array[NUMELEM-1]);

printf("%d",last);
}

/* FUNCTION: largest_element : my resource text says to */
/* make i and j point to the first element of array (but it */
/* does not assume a[0] is the first element for some */
/* reason; f and l are representing first and last elements */
/* of array passed */

int largest_element(int a[], int f, int l)
{
int i=f;
int j=f;

do {
i++;
if (a[i] > a[j]) {
j=i;
}
} while (i != l);

return j;
}

void ascend_sort(int a[],int n)

{
int largest;
int temp;

}

void descend_sort(int a[], int n)
{

}

void random_array(int a[], int n)
{
int i;

for (i=0; i < NUMELEM ; i++)

{
a[i] = rand()%MAXELEM+1;
printf("%3d ",a[i]);

if ((i+1)%10==0)
printf("\n");
}
}```