0 2 56 647 3269
Ascending Original Descending
0 0 3269
2 2 647
56 56 56
647 647 2
3269 3269 0
Press any key to continue
Can anyone know how to print out my original?
what's wrong with my pointer?
#include<stdio.h>
#define SIZE 5
int *rev(int *);
void selectionSort(int *table);
int main(void)
{
int nums[5]={56, 0, 647, 3269, 2};
int g, *p1, *p2, *p3, nnn[5]={0};
p1=nnn;
selectionSort(nums);
p2=nums;
p3=rev(nums);
for(g=0; g<SIZE; g++)
{
nnn[g]=nums[g];
}
printf("Ascending\tOriginal\tDescending\n");
for(g=0; g<SIZE; g++)
{
printf("%d\t\t%d\t\t%d\n", *p2++, *p1++, *p3--);
}
return 0;
}
/*************** rev **************/
int *rev(int *pRev)
{
int i, numPrint;
for(i=SIZE-1, numPrint=0; i>=0; i--)
{
printf("%d ", *pRev++);
}
printf("\n\n");
return(--pRev);
}
/**********SORT *********************/
void selectionSort(int *table)
{
int col, walker, smallest, temp;
for(col=0; col<SIZE; col++)
{
smallest=col;
for(walker=col+1; walker<=SIZE; walker++)
{
if(table[walker] < table[smallest])
{
smallest = walker;
}
}
temp = table[col];
table[col] = table[smallest];
table[smallest] = temp;
}
return;
}



LinkBack URL
About LinkBacks


