/* this program compiles is almost done, but i cannot get the las function to sort numbers from the array. the output should have the even number on the left and odd numbers on the right.*/
#include <stdio.h>
#include <stdlib.h>
#define N 9
void revArray(int *a); /* reverse an array in place */
int *revElement(int *a); /* reverse iterator for array */
void evenOdd(int *a); /* sort array for even/odd order */
int main(int argc, char **argv) {
char x;
int array[N];
int idx;
int *ptr = array;
while(ptr < array + N) {
*ptr++ = array + N - ptr;
}
printf("Original: ");
ptr = array;
while(ptr < array + N) {
printf("%2d ",*ptr++);
}
revArray(array);
printf("\nReversed: ");
ptr = array;
while(ptr < array + N) {
printf("%2d ",*ptr++);
}
printf("\n");
printf("Original: ");
for (idx = 0; idx < N; idx++) {
printf("%2d ",*revElement(array));
}
printf("\n");
/*Put even numbers first, odd numbers last in the array. Order of
the elements is not important as long as all evens are before first odd */
printf("Even: ");
evenOdd(array);
ptr = array;
while(ptr < array + N) {
printf("%2d ",*ptr++);
}
printf("\n");
printf("\nEnter RETURN to continue...");
scanf("%c",&x);
printf("\n[done]\n");
exit(0);
}
void revArray(int *ptr) {
int arr[N], i;
int *s = ptr;
for(i = N-1; i >=0; --i)
{
arr[i] = *ptr++;
}
for(i = 0; i < N; ++i)
{
*(s+i) = arr[i];
}
return;
}
int *revElement(int *ptr) {
static int idx2 = N;
idx2 = --idx2;
return ptr + idx2;
}
void evenOdd(int *ptr)
{
int arr[N], i;
for(i = 0; i < N; ++i)
{
if (arr[N] %2==0)
*ptr;
}
}