---
title: "c语言实现冒泡法排序"
author: "lesorb"
date: "2010-10-16T15:34:49Z"
tags: []
categories: ["编程语言"]
slug: "c"
draft: false
lastmod: "2010-10-16T15:34:49Z"
id: 786363
url: "https://lesorb.iteye.com/blog/786363"
---

c语言实现冒泡法排序，如下：


```c
void _bubbleSort(int a[],int length)
{
	int i,j,temp;
	int bools;
	bools = TRUE;
	for(i=0;i<length-1 && bools;++i)
	{
		bools = FALSE;
		for(j=0;j<length-i;++j)
		{
			if(a[j] > a[j+1])
			{
				temp = a[j];
				a[j] = a[j+1];
				a[j+1] = temp;
				bools = TRUE;
			}
		}
	}
}
```

因为c语言中没有bool类型，注意引用时的头文件声明TRUE和FALSE值分别为1和0：

```c
#define TRUE  1
#define FALSE  0
```