Sorting an Array and one other thing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kaka123
    New Member
    • Dec 2007
    • 8

    Sorting an Array and one other thing

    hey im writing a program where i had a question about sorting an array..in my program i have to sort 3 arrays..does this mean i have to do the sort 3 different time and have 3 "dummy" arrays that will hold the values? i plan on using a interchange sort

    My second question is that i need to Call a function that will return the most frequently occurring exam (scores from a [5][8] array) would i use an if statement to do this? there is 25 total scores in the array.thanks... hopefully i was not to vague on the questions
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Originally posted by kaka123
    hey im writing a program where i had a question about sorting an array..in my program i have to sort 3 arrays..does this mean i have to do the sort 3 different time and have 3 "dummy" arrays that will hold the values? i plan on using a interchange sort

    My second question is that i need to Call a function that will return the most frequently occurring exam (scores from a [5][8] array) would i use an if statement to do this? there is 25 total scores in the array.thanks... hopefully i was not to vague on the questions
    Hi kaka123!
    Your first question is a little vague, but I think I can help a bit.

    First of all, should the sortings of the arrays be independent or not? If they should, you'll have to sort every array separately (at least you have to call them separately at one point or the other). Else, you'll have to call them so they are connected in some way. (There are several ways for doing this, which one is best depends on your program.)
    Now, depending on how you plan to sort your arrays exactly, you might need 3 dummy-arrays or you might not. I'm not quite sure how the "interchang e sort" is supposed to work, I'm just guessing, you want to swap values within your array? If so, you'll only need one temporary value per array. (Or even one all together!) But it really depends on your algorithm.

    My suggestion: Oost your sorting algorithm here (it doesn't have to be in Java yet, it could be pseudocode if you like) and we'll see, if and how it can be improved.

    Concerning your second question, you can write such an algorithm with if-statements or (if the marks are saved with a primitive type) a switch-statement. I'd prefer the second one if possible, as I guess you have more than 2 different possible marks. ^^

    Greetings,
    Nepomuk

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by kaka123
      hey im writing a program where i had a question about sorting an array..in my program i have to sort 3 arrays..does this mean i have to do the sort 3 different time and have 3 "dummy" arrays that will hold the values? i plan on using a interchange sort
      Are those three arrays three independent arrays or do they contain related data,
      e.g. a[i] contains the first name, b[i] the last name and c[i] the age of a person?

      If the latter, the design is no good; if the former there is no problem because if
      you can sort one array you can sort them all, one after another.

      kind regards,

      Jos

      Comment

      Working...