首页 > 代码库 > 桶排序
桶排序
1 #include <iostream> 2 using namespace std; 3 4 5 // 6 // This file contains the C++ code from Program 3.5 of 7 // "Data Structures and Algorithms 8 // with Object-Oriented Design Patterns in C++" 9 // by Bruno R. Preiss.10 //11 // Copyright (c) 1998 by Bruno R. Preiss, P.Eng. All rights reserved.12 //13 // http://www.pads.uwaterloo.ca/Bruno.Preiss/books/opus4/programs/pgm03_05.cpp14 //15 unsigned int const m = 10;16 17 void BucketSort(unsigned int a[], unsigned int n)18 {19 int buckets[m];20 21 for (unsigned int j = 0; j < m; ++j)22 buckets[j] = 0;23 for (unsigned int i = 0; i < n; ++i)24 ++buckets[a[i]];25 for (unsigned int i = 0, j = 0; j < m; ++j)26 //for (unsigned int k = buckets[j]; k > 0; --k)27 if(buckets[j]!=0)28 a[i++] = j;29 }30 int main() {31 32 unsigned int a[4] = {6,3,4,2};33 BucketSort(a,4);34 35 for (int i = 0;i < 4;i++) {36 cout << a[i] << " ";37 }38 cout << endl;39 40 system("pause");41 return 0;42 }
桶排序
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。