本文介绍了从数组获取前10个最高数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题.我有一个带有10个NSMutableArrays的NSMutableDictionary.每个数组都有介于0到10之间的数字,每个数字都可以是任何整数,例如12或103.

I am having a bit of a issue. I have an NSMutableDictionary with 10 NSMutableArrays in it. Each array has somewhere between 0-10 numbers which could each be any integer, e.g. 12 or 103.

我需要做的是从每个数组中获取前10个最高的数字.麻烦的是,我需要在字典(键)中保留来自它的数组的引用以及它来自的数组的编号的索引位置.

What I need to do is get the top 10 highest numbers from across each of the arrays. The trouble is, I need to keep a reference of the array it came from in the dictionary (the key) and the index position of the number from the array it came form.

推荐答案

最简单的方法是按降序对数组进行排序,然后获取前10个索引

Easiest way, is to sort the array in Descending order, and then grab the first 10 indexes

或者如果它们在字典中,则迭代字典allValues,获取所有数组,将所有元素添加到一个公共数组中,然后对其进行排序

Or if they are inside dictionaries, iterate the dictionary allValues, grab all the arrays, add all the elements inside a common array, and sort that

这篇关于从数组获取前10个最高数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-10 23:07