#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include
using namespace std;
void swap(int *a, int *b)
{undefined
int t;
t = *a;
*a = *b;
*b = t;
}
void printArray(int a[], int count)
{undefined
int i;
for(i = 0; i < count; i++)
printf("%d “,a[i]);
printf(”\n");
}
void Odd_even_sort(int a[], int size)
{undefined
bool sorted = false;
while(!sorted)
{undefined
sorted = true;
for(int i = 1; i < size - 1; i += 2)
{undefined
if(a[i] > a[i + 1])
{undefined
swap(&a[i], &a[i + 1]);
sorted = false;
}
}
for(int i = 0; i < size - 1; i += 2)
{undefined
if(a[i] > a[i + 1])
{undefined
swap(&a[i], &a[i+1]);
sorted = false;
}
}
}
}
int main(void)
{undefined
int a[] = {3, 5, 1, 6, 9, 7, 8, 0, 11};
int n = sizeof(a) / sizeof(*a);
Odd_even_sort(a, n);
printArray(a, n);
return 0;
}
c语言实现奇偶排序
于 2020-03-23 12:04:30 首次发布