Results 1 to 12 of 12

Thread: Array problem

  1. #1
    c3jcarmy is offline Member
    Join Date
    Nov 2009
    Posts
    8
    Rep Power
    0

    Red face Array problem

    Dear developers,

    I have a 2D array of an encryption String as seen below..

    C H R I S T --> the header
    D F F G A D
    D A X D A D
    G A Z Z Z Z

    I have to sort the header ascending and form another array as seen below..

    C H I R S T --> the header
    D F G F A D
    D A D X A D
    G A Z Z Z Z

    I have been trying to find a proper logic to solve this.. I was thinking to sort the header first then grab the new index position of every alphabet in the header then move the elements of the header to the new index position.. but i couldn't apply it properly.. Any idea how to solve this? Thanks before..

    Regards,
    c3jcarmy

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Java Code:
    Arrays.sort(yourArray[0]);
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    c3jcarmy is offline Member
    Join Date
    Nov 2009
    Posts
    8
    Rep Power
    0

    Default Wow!

    Wow.. Thanks a lot, PhHein! It works perfectly..!
    Thanks...!

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    You're welcome. Sometimes it helps to know the APIs ;)
    EDIT: Don't forget to mark the thread as solved.
    Last edited by PhHein; 03-10-2010 at 07:40 PM.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  5. #5
    c3jcarmy is offline Member
    Join Date
    Nov 2009
    Posts
    8
    Rep Power
    0

    Default Correction

    I forget to look at the rows below the header, it looks the same.. Do you have any suggestion to change those also? So when the header is sorted, the rows below changes its places to the same index as its header.. Thanks.. :)

  6. #6
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Ooh, that's a little detail that was unclear in your original querstion.

    You should also specify how to handle duplicates in the header, e.g. it's C H A A B?
    Basically you have to provide a mapping: index 0 goes to index 3, index 1 goes to index 4 etc.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  7. #7
    c3jcarmy is offline Member
    Join Date
    Nov 2009
    Posts
    8
    Rep Power
    0

    Post

    Yea, but I already eliminate the duplicates in some part of the program..
    Hmm.. Any suggestion how to make the mapping? Because the the header can be anything that user input.. Thanks... :)

  8. #8
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    If it's a user input, how do you handle an input of: A B A C A?
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  9. #9
    c3jcarmy is offline Member
    Join Date
    Nov 2009
    Posts
    8
    Rep Power
    0

    Default

    It will be ABC and it will make as many rows as it needs to contain all the String and put Z's in extra elements. So it wont return an exception..

  10. #10
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Ok, it works. Use an int [] to store the new ordering, i.e [0, 1, 3, 2, 4, 5]. Then reorder the rows if the 2D char[][].
    EDIT: I know that I'm cryptic, but I want you to find a solution yourself.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  11. #11
    c3jcarmy is offline Member
    Join Date
    Nov 2009
    Posts
    8
    Rep Power
    0

    Smile

    Yea, I need the breakthrough from this problem.. Thanks for your help..:)

  12. #12
    clydedoris is offline Member
    Join Date
    Feb 2010
    Posts
    80
    Rep Power
    0

    Default

    OO concepts would help..try storing the indexes as attributes..
    [why are you annoyed with my sig?]

Similar Threads

  1. Array problem
    By binarzt in forum New To Java
    Replies: 5
    Last Post: 02-14-2010, 09:01 AM
  2. array problem
    By oceansdepth in forum New To Java
    Replies: 3
    Last Post: 04-05-2008, 02:25 AM
  3. Array List Problem
    By khamuruddeen in forum New To Java
    Replies: 1
    Last Post: 12-22-2007, 08:10 AM
  4. array problem
    By wats in forum New To Java
    Replies: 1
    Last Post: 12-12-2007, 07:08 AM
  5. array problem
    By Albert in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 01:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •