Author Topic: Need to store an array number with its respective value  (Read 790 times)

0 Members and 1 Guest are viewing this topic.

Offline Drahgon

  • /dev/null
  • *
  • Posts: 14
  • Cookies: -10
    • View Profile
Need to store an array number with its respective value
« on: December 22, 2015, 12:10:38 am »
Problem:



I can order the numbers .. however I can't seem to find a way to output the ordered values with their respective values in the array that they are originally stored.

Seems almost impossible to me unless there is an inbuilt function that allows you to do it.

Offline zombie

  • /dev/null
  • *
  • Posts: 19
  • Cookies: 3
    • View Profile
Re: Need to store an array number with its respective value
« Reply #1 on: December 22, 2015, 01:15:56 am »
Can you please elaborate more on what your problem is? I don't quiet understand what you are asking.

From what I can tell, it seems like you are asking us to sort an array and then print out the corresponding indices that they were in the unsorted array. Is that correct?

Also, the image you posted is improperly constructed.

Offline Drahgon

  • /dev/null
  • *
  • Posts: 14
  • Cookies: -10
    • View Profile
Re: Need to store an array number with its respective value
« Reply #2 on: December 22, 2015, 03:05:33 am »
Can you please elaborate more on what your problem is? I don't quiet understand what you are asking.

From what I can tell, it seems like you are asking us to sort an array and then print out the corresponding indices that they were in the unsorted array. Is that correct?

Also, the image you posted is improperly constructed.

Sorry, yes that is what I mean :) I have sorted the array correctly but I need to attach the value of {i} that the number was originally stored in. So for example if you have 10 numbers, the 4th number was 6 and so was the 3rd largest .. and the 7th was 5 an and so was the 4th largest .. I would want to output Person 4: 6 .. Person 7: 5 etc

Offline Kurajber

  • Serf
  • *
  • Posts: 43
  • Cookies: 7
  • Don't Drink and Root
    • View Profile
Re: Need to store an array number with its respective value
« Reply #3 on: December 22, 2015, 03:11:18 am »
You can make another array with indexes, and when you switch the values of your first array when sorting, switch the values of that other array also.
0000010100100000

Offline Drahgon

  • /dev/null
  • *
  • Posts: 14
  • Cookies: -10
    • View Profile
Re: Need to store an array number with its respective value
« Reply #4 on: December 22, 2015, 03:51:02 am »
You can make another array with indexes, and when you switch the values of your first array when sorting, switch the values of that other array also.
Cool thanks i'll give that a go :)