Bootstrap

数据结构-----简单排序

1.冒泡排序

//from small to big
void Bubble_Sort(ElementType A[],int N)
{
	for(P=N-1;P>=0;P--)
	{
		flag=0
		for(i=0; i<P; i++)
		{
			Swap(A[i],A[i+1]);
			flag=1;
		}
		if(flag==0)
		break;
	}
}

最好情况:顺序 T=o(N)
最坏情况:o(n^2)
2. 插入排序

void Insertion_sort(ElementType A[],int N)
{
	for(P=1;P<N;P++)
	{
		Tmp=A[P];
		for(i=P;i>0&&A[i-1]>Tmp;i++)
		{
			A[i]=A[i-1];
		}
		A[i]=Tmp; 
	}
}
;