c语言3个数排序算法,将n个数排序的算法,该怎么解决(3)

该博客演示了多种排序算法的实现,包括冒泡排序、插入排序、希尔排序、堆排序和快速排序。通过C语言代码展示了这些算法的详细步骤,并提供了一个用于图形演示排序过程的程序。此外,还分享了一些优化后的排序算法代码和参考资料链接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值