ShellSort(nArray, MAX_ARRAY_SIZE);
break;
case SORT_HEAP:
HeapSort(nArray, MAX_ARRAY_SIZE);
break;
default:
break;
}
printf("\n");
}
return 0;
}
------解决方案--------------------
void bubbleSort(int array[], int length)
{
int i, j, flag, tmp;
for(i = 0; i
{
flag = 1;
for(j = 0; j
{
if(array[j] > array[j + 1])
{
flag = 0;
tmp = array[j];
array[j] = array[j + 1];
array[j + 1] = tmp;
}
}
if(flag == 1)
return;
}
}
冒泡排序优化了下
------解决方案--------------------
1楼 详细
推荐个网站给你
http://student.zjzk.cn/course_ware/data_structure/web/paixu/paixu8.3.2.1.htm
------解决方案--------------------
一楼很全了。我补充几个基数排序,计数排序,桶排序,堆排序。至于代码,LZ百度一下,大把大把的。
------解决方案--------------------
这个是 1992年 Microsoft(R) C/C++, Version 7.0的SORTDEMO
里面有6个sort代码,仅供参考
第一段:
/* SORTDEMO -This program graphically demonstrates six common sorting
* algorithms. It prints 25 or 43 horizontal bars of different lengths
* in random order, then sorts the bars from shortest to longest.
* The program can beep to generate different pitches, depending on the
* length and position of the bar.
*
* This program requires GRAPHICS.LIB.
*/
#include // _outtext, _settextcolor, _settextposition
#include // strlen
#include // sprintf
#include // getch
#include // srand, rand, toupper
#include // malloc, free
#include // time, clock
enum BOOL { FALSE, TRUE };
/* Structure type for colored bars */
typedef struct _BAR
{
char len;
char clr;
} BAR;
/* Structure type for screen cells */
typedef struct _CELL
{
char chChar;
char chAttr;
} CELL;
/* Function prototypes */
void main( void );
void Cls( void );
void InitMenu( void ); // Menu Functions
void DrawFrame( int iTop, int Left, int Width, int Height );
void RunMenu( void );
void DrawTime( int iCurrentRow );
void InitBars( void ); // Bar functions
void ReInitBars( void );
void DrawBar( int iRow );
void SwapBars( int iRow1, int iRow2 );
void Swaps( BAR *one, BAR *two );
void InsertionSort( void ); // Sort functions
void BubbleSort( void );
void HeapSort( void );
void PercolateUp( int iMaxLevel );
void PercolateDown( int iMaxLevel );
void ExchangeSort( void );
void ShellSort( void );
void QuickSort( int iLow, int iHigh );
void Beep( int frequency, int duration );
void Sleep( clock_t wait );
/* Macro */
#define GetRandom( min, max ) ((rand() % (int)(((max) + 1) - (min))) + (min))
#define _outtextxy( ach, x, y ) { _settextposition( y, x ); \
_outtext( ach ); }
/* Constants */
#define ESC 27
#define BLANK 32
#define BLOCK 223
#define TOP 1