Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Need Help: Converting int[] based Radix Sort to string[] based Radix Sort [modified]

Need Help: Converting int[] based Radix Sort to string[] based Radix Sort [modified]

Scheduled Pinned Locked Moved C#
databasecomalgorithmshelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gamer1127
    wrote on last edited by
    #1

    Hello. I got a code here in codeproject.com about radix sorting but it only sorts int based data. I want to use it to sort a string based data. My first try is I got first the ASCII codes of each characters in the strings then passed it in the radix sort code but what it gives me is totally different. This is the link of the code that I got: click here Here is the output after getting the ASCII codes and pass it to the radix sort:

    SHOW DATABASE: SORTING BY LAST NAME

    0

    0

    0

    0

    0

    0

    0

    0

    0

    0

    0

    0

    0

    0

    0

    97

    97

    97

    110

    110

    111

    111

    111

    114

    115

    115

    115

    117

    122

    122

    What should I do for it to be able to sort string?

    modified on Friday, September 4, 2009 6:02 AM

    L L 2 Replies Last reply
    0
    • G gamer1127

      Hello. I got a code here in codeproject.com about radix sorting but it only sorts int based data. I want to use it to sort a string based data. My first try is I got first the ASCII codes of each characters in the strings then passed it in the radix sort code but what it gives me is totally different. This is the link of the code that I got: click here Here is the output after getting the ASCII codes and pass it to the radix sort:

      SHOW DATABASE: SORTING BY LAST NAME

      0

      0

      0

      0

      0

      0

      0

      0

      0

      0

      0

      0

      0

      0

      0

      97

      97

      97

      110

      110

      111

      111

      111

      114

      115

      115

      115

      117

      122

      122

      What should I do for it to be able to sort string?

      modified on Friday, September 4, 2009 6:02 AM

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      It would be more sensible to write a sort routine that accepts strings and sorts them by character order. Alternatively you could use one of the built in List/Array etc types that support sorting via one of their member functions.

      1 Reply Last reply
      0
      • G gamer1127

        Hello. I got a code here in codeproject.com about radix sorting but it only sorts int based data. I want to use it to sort a string based data. My first try is I got first the ASCII codes of each characters in the strings then passed it in the radix sort code but what it gives me is totally different. This is the link of the code that I got: click here Here is the output after getting the ASCII codes and pass it to the radix sort:

        SHOW DATABASE: SORTING BY LAST NAME

        0

        0

        0

        0

        0

        0

        0

        0

        0

        0

        0

        0

        0

        0

        0

        97

        97

        97

        110

        110

        111

        111

        111

        114

        115

        115

        115

        117

        122

        122

        What should I do for it to be able to sort string?

        modified on Friday, September 4, 2009 6:02 AM

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Hi, I don't know why you insist on using radix sort, as it will be slower than a regular sort when sorting strings. Here is how it could work: - determine the length L of the longest string; - treat all strings as having length L by virtually appending NULL characters; - the Nth "digit" of a string has a value that equals the (int) value of its Nth character (where you use zero if N exceeds the string length). So sort all strings according to their (L-1)th character then sort according to their (L-2)th character etc and finally sort according to their first character As I said, it will be slow, as you have to get the characters, one by one, and compare those, whereas a normal sort would be based on a comparer method (such as string.Compare) that takes the whole string into account right away. :)

        Luc Pattyn

        :badger: :jig: :badger:

        Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.

        :jig: :badger: :jig:

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups