前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >计数排序—C++

计数排序—C++

作者头像
WindCoder
发布2018-09-20 15:01:49
4280
发布2018-09-20 15:01:49
举报
文章被收录于专栏:WindCoderWindCoder
代码语言:javascript
复制
/*
功能:03计数排序
作者:wind
日期:2014-01-11
*/

#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 10;
typedef int KeyType;
typedef struct
{
	KeyType key;
	char data;
}RedType;
typedef struct
{
	RedType r[11];
	int length;
}SqList;
void InsertSort (SqList *L,int n)
{
	int *c=new int[11];
    int i,j;
	RedType tmp = L->r[1];
	//计算c[i]
	for(i =1;i<L->length;i++)
	{
		for( j=2;j<L->length;j++)
		{
			if (L->r[i].key<L->r[j].key)
			{
				c[i]++;
			}
		}

	}
	//按C[i]排序
	for(i = L->length;i>1;i++)
	{
		for(int j=1;j<L->length;j++)
		{
			if (c[i]<c[j])
			{
				 tmp = L->r[j];
				  L->r[i] = L->r[j];
				  L->r[j] = tmp;
			}
		}
	}
	delete[] c;
}
int main(void)
{




	system("pause");
	return 0;
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2014-11-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档