DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  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 =-

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links