Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1750111
  • 博文数量: 600
  • 博客积分: 10581
  • 博客等级: 上将
  • 技术积分: 6205
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-06 10:13
文章分类
文章存档

2016年(2)

2015年(9)

2014年(8)

2013年(5)

2012年(8)

2011年(36)

2010年(34)

2009年(451)

2008年(47)

分类:

2011-05-15 11:12:20

#include
using namespace std;

struct nod
{
 float value;
 struct nod *next;
};
class bucket_sort
{
 public:
  bucket_sort();
  ~bucket_sort();
  void output();
  void bucketsort();
 private:
  float *a;
  int leng;
  struct nod **head;
};
void bucket_sort::bucketsort()
{
 struct nod *pnod,*p;
 for(int i="0";i {
  pnod=new struct nod;
  pnod->value=a[i];
  
  if(head[(int)(leng*a[i])]==(struct nod *)0)
  {
   pnod->next=(struct nod *)0;
            head[(int)(leng*a[i])]=pnod;
  }
  else
  {
   struct nod *pold;
   for(pold=p=head[(int)(leng*a[i])];(p!=(struct nod *)0)&&(p->valuenext)
   {
    pold=p;
   }
   if(p==(struct nod *)0)
   {
    pnod->next=(struct nod *)0;
    pold->next=pnod;
   }
   else
   {
    if(p==head[(int)(leng*a[i])])
    {
                    head[(int)(leng*a[i])]=pnod;
    }
    else
    {
                 pold->next=pnod;
    }
                pnod->next=p;
   }
  }
 }
 cout<<"桶中的分布情况:\n";
 for(int i="0",j=0;i {
  for(p=head[i];p!=(struct nod *)0;p=p->next)
  {
   a[j++]=p->value;
   cout<value<<" ";
  }
  cout< }
}
bucket_sort::~bucket_sort()
{
 for(int i="0";i {
       
  while(head[i]!=(struct nod *)0)
  {
   struct nod *p=head[i];
   while(p->next!=(struct nod *)0)
   {
    p=p->next;
   }
   delete p;
  }
 }
 delete[] head;
}
bucket_sort::bucket_sort()
{
    cout<<"请输入参加排序小数的个数\n";
 cin>>leng;
 a=new float[leng];
 for(int i="0";i {
  cout<<"请输入第"<  cin>>a[i];
 }
 head=new struct nod *[leng];
 for(int i="0";i {
  head[i]=(struct nod *)0;
 }
}
void bucket_sort::output()
{
 cout<<"现在数组中的数字分别为:\n";
 for(int i="0";i {
  cout< }
 cout<}
int main()
{
 bucket_sort test;
 test.output();
 cout<<"正在排序...\n";
 test.bucketsort();
 cout<<"完成!\n";
 test.output();
 return 0;
}
阅读(1954) | 评论(0) | 转发(0) |
0

上一篇:红黑树

下一篇:基数排序C++实现

给主人留下些什么吧!~~