数据结构与算法:冒泡排序

冒泡排序代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
void bubbleSort(int *p , int n)
{
for (int i=0; i<n-1; i++)
{
for (int j=i+1; j<n; j++)
{
if (p[j] < p[i])
{
p[i] ^= p[j];
p[j] ^= p[i];
p[i] ^= p[j];
}
}
}
}


int main()
{
int a[5] = {3, 1, 4, 2, 5};
bubbleSort(a, 5);

for (int i=0; i<5; i++)
{
printf("%d\t", a[i]);
}
return 1;
}

#

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×