#How can I sort info inside 3D arrays?

8 messages · Page 1 of 1 (latest)

devout pendant
#

I am using C/C++ and I want to create a 3D array which holds CITY-DAY-TEMPERATURE, but I also want the program to print the information in ascending order. The program doesn't need to scan info.

Basically I want my output to be:

City 1, Day 1, Temperature = 26°C
City 1, Day 2, Temperature = 29°C
City 2, Day 1, Temperature = 17°C
City 2, Day 2, Temperature = 15°C
City 3, Day 1, Temperature = 22°C
City 3, Day 2, Temperature = 24°C

COLDEST DAYS:
City 2, Day 2, Temperature = 15°C
City 2, Day 1, Temperature = 17°C
City 3, Day 1, Temperature = 22°C
City 3, Day 2, Temperature = 24°C
City 1, Day 1, Temperature = 26°C
City 1, Day 2, Temperature = 29°C

Could anyone help? I know the basics about C but I have no idea how to sory information in 3D arrays.

burnt whale
#

Hmm, i assume you'd want to sort by the temperature?

devout pendant
#

Yeah!

burnt whale
#

Hmm, 👀 well you can look into sorting algorithms, and one options also (well not economic thou) would be to create a new array and loop through one you have and insert values from it into new array,
By some criteria 🙁

devout pendant
#

i tried but i cant make the code work
:( i also don't know how to only call one dimension for the array so i can compare it

burnt whale
#

Also i think you could look into algorithm library (cpp) myb some function from there can help

devout pendant
#

I'll look into it

burnt whale
#

And basically you wouldn't call only one dimension 😮