数据结构与算法学习笔记——quick sort

来源:互联网 发布:adobe输出软件 编辑:程序博客网 时间:2024/05/16 07:56

无任何营养,仅仅记录学习路程

.C文件

/****************************************************************** Copyright(C):* Filename:* Author:* Version:* Date:* Description:*****************************************************************/#include "quick_sort.h"//----------------------------------------// Swap()//////voidSwap(ElementType *X, ElementType *Y){ElementType a;a = *X;*X = *Y;*Y = a;}//----------------------------------------// Partion()//////int Partion(ElementType *A, int p, int q){int i,j,x;i = p;x = A[ p ];for ( j=p+1; j<=q; j++  ){if ( A[j] < x ){Swap(&A[i+1], &A[j]);i++;}}Swap(&A[p],&A[i]);return i;}//----------------------------------------// QuickSort()//////void QuickSort(ElementType *A, int p, int q){int r;if ( p >= q ){return;}r = Partion(A,p,q);QuickSort(A,p,r-1);QuickSort(A,r+1,q);}


.h文件


/***************************************************** Copyright(C):* Filename:* Author:* Version:* Date:* Description:*****************************************************/#ifndef QUICK_SORT_H#define QUICK_SORT_Htypedef int ElementType;void QuickSort(ElementType *A, int p, int q);#endif // QUICK_SORT_H


原创粉丝点击