Internal Sorting: Radix sort: Sorting by Exchanging
来源:互联网 发布:电脑滚动字幕软件 编辑:程序博客网 时间:2024/06/07 13:52
Java program
/** * Created with IntelliJ IDEA. * User: 1O1O * Date: 11/30/13 * Time: 10:01 PM * :)~ * Radix sort:Sorting by Exchanging:Internal Sorting */public class Main { public static void main(String[] args) { int N = 16; int[] K = new int[17]; int[][] D = new int[4][17]; int digit_len = 3; int temp; int tempDigit; /*Prepare the data*/ K[1] = 503; K[2] = 87; K[3] = 512; K[4] = 61; K[5] = 908; K[6] = 170; K[7] = 897; K[8] = 275; K[9] = 653; K[10] = 426; K[11] = 154; K[12] = 509; K[13] = 612; K[14] = 677; K[15] = 765; K[16] = 703; /*Output unsorted Ks*/ System.out.println("Unsorted Ks:"); for(int i=1; i<=N; i++){ System.out.println(i+":"+K[i]); } System.out.println(); /*Kernel of the Algorithm!*/ for(int i=1; i<=digit_len; i++){ for(int j=1; j<=N; j++){ switch (i){ case 1: D[1][j] = K[j]%10; break; case 2: D[2][j] = (K[j]/10)%10; break; case 3: D[3][j] = K[j]/100; break; } } /*Stable bubble sort*/ for(int BOUND=N; BOUND>1; BOUND--){ for(int m=1; m<=BOUND-1; m++){ if(D[i][m] > D[i][m+1]){ tempDigit = D[i][m]; D[i][m] = D[i][m+1]; D[i][m+1] = tempDigit; temp = K[m]; K[m] = K[m+1]; K[m+1] = temp; } } } System.out.println("The "+i+" digit sorted Ks:"); for(int n=1; n<=N; n++){ System.out.println(n+":"+K[n]); } System.out.println(); } /*Output sorted Ks*/ System.out.println("Final sorted Ks:"); for(int i=1; i<=N; i++){ System.out.println(i+":"+K[i]); } }}
Outputs
Unsorted Ks:1:5032:873:5124:615:9086:1707:8978:2759:65310:42611:15412:50913:61214:67715:76516:703The 1 digit sorted Ks:1:1702:613:5124:6125:5036:6537:7038:1549:27510:76511:42612:8713:89714:67715:90816:509The 2 digit sorted Ks:1:5032:7033:9084:5095:5126:6127:4268:6539:15410:6111:76512:17013:27514:67715:8716:897The 3 digit sorted Ks:1:612:873:1544:1705:2756:4267:5038:5099:51210:61211:65312:67713:70314:76515:89716:908Final sorted Ks:1:612:873:1544:1705:2756:4267:5038:5099:51210:61211:65312:67713:70314:76515:89716:908
0 0
- Internal Sorting: Radix sort: Sorting by Exchanging
- Internal Sorting: Radix exchange sort: Sorting by Exchanging
- Internal Sorting: Bubble sort: Sorting by Exchanging
- Internal Sorting: Merge exchange sort: Sorting by Exchanging
- Internal Sorting: Cocktail-shaker sort: Sorting by Exchanging
- Internal Sorting: Quicksort-2: Sorting by Exchanging
- Internal Sorting: Quicksort-1:Sorting by Exchanging
- Internal Sorting: Radix List Sort: Sorting by Distribution
- Comb sort: Sorting by Exchanging
- Gnome sort: Sorting by Exchanging
- Stooge sort: Sorting by Exchanging
- Odd-even sort: Sorting by Exchanging
- Optimized Gnome sort: Sorting by Exchanging
- Bogosort: Sorting by Exchanging
- Bozosort: Sorting by Exchanging
- Internal Sorting: List Merge Sort: Sorting by Merging
- Internal Sorting: Straight Two-way Merge Sort: Sorting by Merging
- Internal Sorting: Natural Two-way Merge Sort: Sorting by Merging
- solr分页查询和高亮
- poj 1182 食物链 【带权并查集】
- 用回溯法解决0-1背包问题
- Android之Intent原理
- iOS核心面试题 ~
- Internal Sorting: Radix sort: Sorting by Exchanging
- Python之学习笔记(高级特性)
- 设计模式之二:策略模式(Strategy)
- redis主从配置
- UBUNTU LOG 5-31隐藏Ubuntu分区
- jstack排查定位线程
- Java中的反射及Bean容器的实现
- css盒子模型
- ARM进阶笔记一