sorting

Sort an array with special characters - iPhone

南笙酒味 提交于 2020-01-11 11:00:12
问题 I have an array with french strings let say: "égrener" and "exact" I would like to sort it such as égrener is the first. When I do: NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES]; NSArray *sortDescriptors = [NSArray arrayWithObject:descriptor]; NSArray *sortedArray = [myArray sortedArrayUsingDescriptors:sortDescriptors]; I get the é at the end of the list... What should I do? Thanks 回答1: There’s a convenience method in NSString that lets you do

Performance on Java ArrayList vs LinkedList, pertaining to only Creation/Insertion and sorting

六眼飞鱼酱① 提交于 2020-01-11 10:50:09
问题 Consider the following code: import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; import java.util.List; public class testSortingSpeed { public static final int TOTAL_NUMBER = 10000000; public static void main(String[] args) { System.out.println("Creating ArrayList:"); List<Pair<Integer, Integer>> a = new ArrayList<>(); long start = System.currentTimeMillis(); for (int i = 0; i < TOTAL_NUMBER; i++) { Pair<Integer, Integer> p = new Pair<>( (int ) Math.random()

How to allow Web Workers to receive new data while it still performing computation?

妖精的绣舞 提交于 2020-01-11 10:44:29
问题 I want to sort an array, using Web Workers. But this array might receive new values over time, while the worker is still performing the sort function. So my question is, how can I "stop" the sorting computation on the worker after receiving the new item, so it can perform the sort on the array with that item, while still keeping the sorting that was already made? Example: let worker = new Worker('worker.js'); let list = [10,1,5,2,14,3]; worker.postMessage({ list }); setInterval(() => worker

How to allow Web Workers to receive new data while it still performing computation?

人走茶凉 提交于 2020-01-11 10:44:07
问题 I want to sort an array, using Web Workers. But this array might receive new values over time, while the worker is still performing the sort function. So my question is, how can I "stop" the sorting computation on the worker after receiving the new item, so it can perform the sort on the array with that item, while still keeping the sorting that was already made? Example: let worker = new Worker('worker.js'); let list = [10,1,5,2,14,3]; worker.postMessage({ list }); setInterval(() => worker

Achieving consistent sorting between c# and SQL using CollationInfo.Comparer

耗尽温柔 提交于 2020-01-11 10:03:07
问题 I am attempting to use CollationInfo.Comparer from SMO to get my c# code to sort like SQL Server. I have gotten the correct collation, but my items still do not sort correctly. var collationInfo = CollationInfo.Collations.Single(x => x.Name == "SQL_Latin1_General_CP1_CS_AS") as CollationInfo; var comparer = collationInfo.Comparer; int c = comparer.Compare("Tri-Valley L", "Trimble L"); In this case c returns '1' indicating that Tri-Valley L will come after Trimble. However this code in SQL

Conditional sorting in MySQL?

偶尔善良 提交于 2020-01-11 09:58:47
问题 I have "tasks" table with 3 fields: date priority (0,1,2) done (0,1) What I am trying to achieve is with the whole table sorted by done flag, tasks that are not done should be sorted by priority, while tasks that are done should be sorted by date: Select * from tasks order by done asc If done=0 additionally order by priority desc If done=1 additionally order by date desc Is it possible to do this in MySQL without unions? Thanks. 回答1: You could try ORDER BY (done asc, aux desc) where aux is

Using Union All and Order By in MySQL

女生的网名这么多〃 提交于 2020-01-11 09:42:46
问题 I've 2 tables: create table advertised_products(id int,title varchar(99),timestamp timestamp); insert advertised_products select 1,'t1',curdate(); create table wanted_products(id int,title varchar(99),timestamp timestamp); insert wanted_products select 1,'t1',now(); I'm using this query to get the records: ( SELECT ap.*, 'advertised' as type FROM advertised_products as ap ) union all ( SELECT wp.*, 'wanted' as type FROM wanted_products as wp ) ORDER BY timestamp desc limit 3 But it gives

Using Union All and Order By in MySQL

穿精又带淫゛_ 提交于 2020-01-11 09:42:13
问题 I've 2 tables: create table advertised_products(id int,title varchar(99),timestamp timestamp); insert advertised_products select 1,'t1',curdate(); create table wanted_products(id int,title varchar(99),timestamp timestamp); insert wanted_products select 1,'t1',now(); I'm using this query to get the records: ( SELECT ap.*, 'advertised' as type FROM advertised_products as ap ) union all ( SELECT wp.*, 'wanted' as type FROM wanted_products as wp ) ORDER BY timestamp desc limit 3 But it gives

Sort dataframe by first column, Pandas

空扰寡人 提交于 2020-01-11 09:38:52
问题 I have a dataframe with one column, which I would like to sort. Typing following code gives me a sorted dataframe: sort = tst.sort(["Mean"], ascending = False) Mean SIMULATION Sim_758 1.351917 Sim_215 1.072942 Sim_830 0.921284 Sim_295 0.870272 Sim_213 0.845990 Sim_440 0.822394 This will be part of a function, which will be applied to other dataframes. For this reason I need to sort the dataframe without mentioning the column name "mean". Is there a way to sort a dataframe by the values of a

Sort String array in custom order

那年仲夏 提交于 2020-01-11 09:38:14
问题 I want to sort a fixed set of strings like "Text files", "Image files", "Audio files", "Video files", "Application Files", "Other files" in a string array in the same order I have mentioned. Example1, if my string array input is like this inputval[0] = "Other files"; inputval[1] = "Image files"; inputval[2] = "Text files"; my output array should have values like this outputval[0] = "Text files"; outputval[1] = "Image files"; outputval[2] = "Other files"; Example 2, if my string array input is