=====
Question 2nd: Odd and even sort (i)
=====
Total time limit:
1000ms
Memory Limit:
65536kB
Describe
Enter 10 integers, the 10 integers in ascending order, and the odd number before, even after.
Input
Enter 10 integers
Output
10 integers sorted according to parity
Copy Code code as follows:
#include <stdio.h>
#define COUNT 10
#define BOOL INT
#define TRUE 1
#define FALSE 0
/****
* Responsible for bubble sort
***/
int* sortfunction (int data[]) {
int i,j;
for (j=0;j<count-1;j++) {
for (i=0;i<count-1-j;i++) {
if (Data[i]>data[i+1]) {
int tmp=data[i]; DATA[I]=DATA[I+1];d ata[i+1]=tmp;
}
}
}
return data;
}
/****
* * is responsible for judging odd or even
*/
BOOL Isoddnumber (int data) {
If (data% 2==0) {
return false;
}else{
return true;
}
}
Main ()
{
int arr[]={10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
int oddarr[count]={0},evenarr[count]={0};
int *tmp=null;
int i;
int m=0;
int n=0;
for (i=0;i<count;i++) {
if (Isoddnumber (Arr[i])) {
Evenarr[m++]=arr[i];
}else{
Oddarr[n++]=arr[i];
}
}
For odd array sorting
Tmp=sortfunction (Oddarr);
Puts ("\n========odd number==========\n");
for (i=0;i<count;i++) {
int num=*tmp;
if (num!=0)
{
printf ("%d", num);
}
*tmp++;
}
Ordering for even arrays
Tmp=sortfunction (Evenarr);
Puts ("\n========even number==========\n");
for (i=0;i<count;i++) {
int num=*tmp;
if (num!=0)
{
printf ("%d", num);
}
*tmp++;
}
printf ("Over");
}
The above code is written and completed in vs2012.