sorting

How to sort a file in unix both alphabetically and numerically on different fields?

↘锁芯ラ 提交于 2021-02-05 17:58:19
问题 Please don't think this is a repeat of the "Sorting alphanumeric data in unix" question... I looked at the other answers, and think my case is a bit different! I have data like this: A 192 D 112 D 188 C 091 A 281 B 919 ...And I want to sort first column 1 (alphabetically), and then by column 2 (numerically). I tried using: sort -n -k1,2 ...But this gave me correctly sorted for the first field, but then the wrong sorting for the second field (1000,1002,1003,10,1 ... instead of 1,10,1000,1002

sort files by size error in c#

故事扮演 提交于 2021-02-05 12:28:33
问题 I have a little problem sorting files. My program should allow me to sort the files of a directory by size and by date. The date works fine but when I try to sort by size, it returns an error. This is my relevant code: if (orden.Equals("tam")) { ficheroo = dirInfoo.GetFiles(filtro, SearchOption.AllDirectories).OrderBy(f => new FileInfo(f).Length).ToList(); } the error is in the use of new FileInfo(f).Length and the error is: La mejor coincidencia de método sobrecargado para 'System.IO

Find all possible combinations that overlap by end and start

ⅰ亾dé卋堺 提交于 2021-02-05 11:22:06
问题 In the post find all combinations with non-overlapped regions (code pasted below), the function is given a set of tuples and it recursively finds every possible collection of tuples with non-overlapping values. On the list of tuples T = [(0.0, 2.0), (0.0, 4.0), (2.5, 4.5), (2.0, 5.75), (2.0, 4.0), (6.0, 7.25)] , for example, we get def nonovl(l, idx, right, ll): if idx == len(l): if ll: print(ll) return next = idx + 1 while next < len(l) and right >= l[next][0]: next += 1 nonovl(l, next,

StackOverflowException when perform Quicksort with ordered list

喜夏-厌秋 提交于 2021-02-05 11:14:10
问题 I'm implementing Quick sort algorithm in C#. Implementation as follow: /// <summary> /// Perform Sort /// </summary> /// <returns></returns> public override List<int> Sort(List<int> list) { try { this.quick(ref list, 0, list.Count - 1); return list; } catch (Exception) { throw; } } /// <summary> /// Quick sort main algorithm /// </summary> /// <param name="list"></param> /// <param name="left"></param> /// <param name="right"></param> private void quick(ref List<int> list, int left, int right

Python - sorting strings numerically

风格不统一 提交于 2021-02-05 10:44:07
问题 I'm using python to merge two files together to create a new one, the data in both files have an id at the start of every string which I want to sort so they're both in the same order and can be merged. To do this I've used .sort() so that they're both arranged in the same order and the comments match the details. However, I'd now like to reorder them so that they go 1, 2, 3, 4... instead of 1, 10, 100, 1000, 1001, 1002 etc but I am having difficulties since the number is the start of a

R: Sorting all columns in data frame by an alphanumeric column

倾然丶 夕夏残阳落幕 提交于 2021-02-05 10:37:15
问题 I want to sort all columns of a data frame in R by a column containing alphanumeric data. Here is an example data frame: R> dd <- data.frame(b = c("Hi", "Med", "Hi", "Low"), x = c("A", "D", "A", "C"), y = c(8, 3, 9, 9), z = c("A1", "A3", "A10", "A2")) 1 Hi A 8 A1 2 Med D 3 A3 3 Hi A 9 A10 4 Low C 9 A2 I would like to sort the entire data frame on column z. The desired output looks like this - with the info across columns staying consistent: 1 Hi A 8 A1 2 Low C 9 A2 3 Med D 3 A3 4 Hi A 9 A10

Order by list in complex object

此生再无相见时 提交于 2021-02-05 10:01:47
问题 I have two classes : public class Customer { public string FirstName { get; set; } public string LastName { get; set; } public List<Product> Product { get; set; } } public class Product { public int ProductNumber { get; set; } public string ProductColor { get; set; } } And one instance : Customer Cus = new Customer() { FirstName = "FirstName1", LastName = "LastName1", Product = new List<Product> { new Product() { ProductColor = "ProductColor12", ProductNumber = 12 }, new Product() {

How to sort without considering special characters in java?

天涯浪子 提交于 2021-02-05 10:00:50
问题 I wanted to sort a list of names and I used compareTo method and I have names like this on my list $urya, andy, prince, @rikesh, expected output: andy, prince, $urya, @rikesh, instead, I get: $urya @rikesh andy prince What happens now is the name that starts with special characters come's first and then other names are sorted Is there a way to push the names that starts with special characters to last. if (this.firstName == name.firstName) { return 0; } else if (this.firstName == null) {

Sort a move to end list

我们两清 提交于 2021-02-05 09:48:56
问题 A sequential unique list of numbers (1,2,3,...,n) has been randomized and I need to sort it by moving one item at a time to the end of the list. Which algorithm will provide the least number of moves? Note: [123645] can be sorted with 1 move, [125346] in 2 moves, [654321] will need 5 moves. I'd like an algorithm that can account for these, not one that just gives me n-1 all the time. Best I can think of: for(var x=1; x<=list.length; x++) if indexOf(x+1)<indexOf(x) then move x+1 to end Does

Sorting by DATE and TIME using Comparator

筅森魡賤 提交于 2021-02-05 09:45:34
问题 I am trying to sort the objects by Date and Time -> for example if the dates and times are: 24/04/2015 14:00 & 24/04/2015 09:00 & 25/04/2015 15:00 order should be this: 24/04/2015 09:00 24/04/2015 14:00 25/04/2015 15:00 In my case the order is this: 24/04/2015 14:00 24/04/2015 09:00 25/04/2015 15:00 It gets sorted by date, but ignores the time. The code Collections.sort(myObjects, new Comparator<MyObject>(){ @Override public int compare(MyObject object1, MyObject object2) { return object1