On sorting an array i get : 1,10,2,3,4,5,6,7,8,9. What went wrong ?

My code was:

```
NSArray *sortedArray = [optionKeys sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
```

where optionKeys were: 7,3,8,4,9,5,1,6,2,10

i had also tried CaseInsensitiveCompare: and got the same result.

String comparison will place 10 after 1. You'll need to use a number comparison function. This may help: How to let the sortedarrayusingselector using integer to sort instead of string

You're doing a string sort rather than a numeric sort. See this answer.

Check out this answer. You want to do a numeric sort instead of a string sort.

Similar Questions

I have a list filled with the numbers 3, 7, 10, 8, 12. I'd like to write a line that will tell me which element in the list is not sorted (in this case it is the 4th element). However, the code I have

Similar question has been asked for a sorted list here, but the solution used bisect which is not working for reserve sorted list. Say I have a list, sorted in reverse order, keyed on the middle elem

I would like to have an observable array which will sort itself when an object is pushed into it (it would be even better if it would sort itself if any of the values it was using in the comparator fu

I was preparing for a competition and came across this question, which I can't comprehend. Consider a set of 'n' elements in an array, which is sorted except for one element that appears out of order.

I have record in which one field is list: -record(state, { rcpt :: list() }). Rcpt field has some values = [localhost, admin] I need filter this list. For example i need field localhost. I try

I have a List<> that I've previously sorted by one of the fields on the object. If I perform a Where() on the list, am I safe to assume that the results of the Where will also be sorted? // Sort

I have seen answers to the question: Is it possible to arrange a numpy array (or python list) by using the indexes of the elements in decreasing order? (eg. Finding the Index of N biggest elements in

I have an array with a list of objects sorted alphabetically ignoring the letters case (used a lowerCaseString method) and I need to sort it into an array of arrays one for each letter +1 for non alph

Is there an optimized function in any numerical library (MKL, Boost, GSL,..etc) that searches a sorted array of floating point numbers for the closest match to a given float? Another function which wi

What is the complexity of search in sorted std::list? I knew that complexity of search in sorted data is O(log n) if the data structure has random access. But since list doesn't have random access, wh

I am making a doubly linked list using a struct ListItem which has prev and next pointers and a value of type T. Am I doing it right? When I run the main code, I can see only 1, 15, and 16 in the disp

I have several sorted lists, and I want to add them together into one big sorted list. What is the most efficient way to do this? Here is what I would do, but it is too inefficient: big_list=[] for sl

So I have an array like the following: Array ( [0] => Array ( [user_id] => 684 [sec_id] => 2 [rank_id] => 1 [rank] => usr ) [1] => Array ( [user_id] => 693 [sec_id] => 3 [rank_

Suppose given an array of size n, with sorted values. In iteration i, a new random-generated value is given, and inserted into the end of the array. The array is then resorted, and discard the least

I want to generate some test data to test a function that merges 'k sorted' lists (lists where each element is at most k positions away from it's correct sorted position) into a single fully sorted li

I have an array with values as follows: 0-10 10-50 50-100 100-150 150-200 200+ This is actually an array of WordPress taxonomies, which WP sorts alphabetically (or ascending order of the first digit)

I have this code that I have been working on for a couple of hours now trying to figure out how to implement removing duplicates within the sorted array during the insertion sort. I'm trying to do thi

I am currently working on this coding problem for class. Given a sorted array of n distinct values as well as a target value T, determine in O(n) time whether or not there exist two distinct values in

The dir() function return a list of the methods but: The resulting list is sorted alphabetically I want to know which ones are but not sorted alphabetically. I use the name to help to understand wha

Given a sorted array A[1...n] of keys, and another key, x, stored in A, show how to find the index, k, so that A[k] = x in time O(log(k)). I know that a binary search on a sorted array would be comple

I´m searching for a sorted Array or Map (Dict...whatever) in Objective-C on iOS. Is there something comparable (sorting when inserting) or do I have to override the getter/setter and sort the data str

I am getting values which are sorted from a plist and displaying them in a tableview. I am providing the capability of entering a custom category which will be written to plist. But I want that to be

I made an array, but I confused as how to dispaly the array contents depanding on a random generator. E.g. If there are four statements in my array, and when I run the program I get number 3, I would

Is there a way to perform a partial sort on an array of data so that the last n elements are sorted? By good I mean using the standard library, not implementing my own sort function (this is what I'm

If searching a sorted List is O(log2 n) and searching a balanced BST is also O(log2 n), which one should I use assuming the following: Elements will be received unsorted and then sorted after all the

I have created a Balanced BST from a sorted array, my question is how to test it. Simply testing that if a tree is balanced or not will not help, as even a binary tree (note - mentioned Binary tree, n

I want a sorted list of files from a directory. How do I apply the sort function to a list with IO monad? import System.Directory import Data.List sortedFiles :: FilePath -> IO [FilePath] sortedFil

I have a 2 dimensional array. The rows and columns are sorted. How to find the kth largest element from the 2-d array?

I'm looking for a good sorted list for java. Googling around give me some hints about using TreeSet/TreeMap. But these components is lack of one thing: random access to an element in the set. For exam

I have the following code: //data_r is an array with values var i = 0; var sort_order = new Array(); data_r.sort(function (a,b) { var res = a[0] - b[0]; sort_order[i] = res; i++; return res; }); In t

Skiena, in The Algorithm Design Manual, states that insertion into a sorted array is O(n). Yet searching for an item in a sorted array is O(log n), because you can do a binary search. Couldn't inserti

I have an array of objects of the following form: arr[0] = { 'item1' : 1234, 'item2' : 'a string' }; I sort it first by 'item1' which is straightforward. Now i want to sort arr (which is sorted by 'i

I was asked the below question in an interview: Given an array of integers, write a method to find indices m and n such that if you sorted elements m through n, the entire array would be sorted. Minim

Suppose a method has been written that expects a sorted list as one of its input. Of course this will be commented and documented in the code, param will be named sortedList but if someone forgets,

I am trying to code a c++ program for sorted insert of a linked list. I have given the code below. The problem is when doing my second insert i.e., insert(&head, 45); the head value is becoming 0

There seems to be a problem in add method of the class I have written.. I want to make a SortedList using an array, but I can't figure out what the problem is. This is my code: public class SortedList

I'm wondering, is there any difference between performance of those, provided binary search is used for sorted linked list insertion, search. And in which situations they perform differently or maybe

I have a program like this public class no_of_letters_count { static int i; public static void main(String[] args) { String sMessage=hello how r u; String saMessage[] = sMessage.split(); List sLis

I have a list of news unsorted items, some of which have a priority flag. I need the priority items to float to the top of the list, and then sort the rest by a date. So, the end result is a list of

Hi I have a linked list using structs. Right now I got it to add every element at the end. However I'd like to add each element in sorted order based on the ID. The struct has two elements: string nam

I'm trying to find the fastest way to find the first non-zero value for each row of a two dimensional sorted array. Technically, the only values in the array are zeros and ones, and it is sorted. Fo

I recently faced a programming problem which is as follows: A sorted array is given and the array is rotated at some unknown point, I have to find the minimum element in it. The Array can contain dupl

Suppose you have a sorted List containing server names. You'd like to collapse them as tightly as possible. Example: abcd01c, abcd02c, abcd04c, abcd05, z1x should become abcd0[1-4]c,abcd05,z1x What

I'm trying to convert a Map to an ordered List based upon the values in the Map. Suppose I have the following: Map<String, Integer> map = Maps.newHashMap(); map.put(foo, 1); map.put(boo, 3);

I was asked this interview question recently: You're given an array that is almost sorted, in that each of the N elements may be misplaced by no more than k positions from the correct sorted order. F

i'm trying to implement a search method, which returns a index of a object where it should be inserted in a sorted list, recursively. Here is my attempt. //listSize is the number of elements inside

Suppose you have an array of 3 billion integer that are almost sorted. What sorting algorithm would be more appropriate (from amongst the classic ones)? How about if the list was completely random?

This is more of a conceptual question concerning the built in functionality of PHP and arrays. I was wondering if there is any way to do the following: You have an array $a and this array contains 5 e

I have sorted array with numbers as keys, I need a reasonably fast alg to pick a key number which is holding value closest or identical (if exists) to given variable. If given value is higher than max

I'm working on an AVL tree assignment and I have a quick question about their definition - we're given a sorted list, and we have to generate an AVL tree from it in O(n) time. I've completed this (tha