Help with ->Straight Radix Sort


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Help with ->Straight Radix Sort

  1. #1
    Join Date
    Jan 2005
    Posts
    9

    Help with ->Straight Radix Sort

    I must make a class wich read 10 numbers eg 5,3,8,6,4,1,9,2,0,7,8
    and sort them with Straight Radix Algorithm!

    the Algorithm is:
    PHP Code:
    class StraightRadixSort {

        static final 
    int w 71;
        static final 
    int M = (int) Math.pow(2m);

        
    int bits(int xint kint j
            { return (
    >> k) & ~(~<< j); }

        
    void straightradix(int a[]) {
            
    int ijpassa.length;
            
    int b[] = new int[N];
            
    int count[] = new int[M];
            for (
    pass 0pass w/mpass++) {
                for (
    0Mj++) count[j] = 0;
                for (
    0Ni++)
                    
    count[bits(a[i], pass*mm)]++;
                for (
    1Mj++)
                    
    count[j] += count[j-1];
                for (
    N-1>= 0i--) 
                    
    b[--count[bits(a[i], pass*mm)]] = a[i];
                for (
    0Ni++) { a[i] = b[i];  }
            }
        }

        
    void sort(int a[]) {
            
    straightradix(a); 
        }

    can anyone help me with the main()


    -= SpY =-

  2. #2
    Join Date
    Nov 2004
    Location
    Norway
    Posts
    1,560
    Code:
      public static void main(String[] args) {
        // make an integer array for sorting
        int [] sortArray = {
            5,3,8,6,4,1,9,2,0,7,8
        };
        // make an instance of the StraightRadixSort class
        StraightRadixSort srs = new StraightRadixSort();
        // invoke the StraightRadixSort class' sort() method
        srs.sort(sortArray);
        // print out the sorted array
        for (int i=0;i<sortArray.length;i++) {
          System.out.println(sortArray[i]);
        }
      }
    eschew obfuscation

  3. #3
    Join Date
    Jan 2005
    Posts
    9

    Thumbs up

    sjalle
    Thanks man ! tnx w much


    -= SpY =-

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center