sort

C# Sort files by natural number ordering in the name?

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have files in directory like that 0-0.jpeg 0-1.jpeg 0-5.jpeg 0-9.jpeg 0-10.jpeg 0-12.jpeg .... when i loading files: FileInfo[] files = di.GetFiles(); They getting in wrong order (they should go like above): 0-0.jpeg 0-1.jpeg 0-10.jpeg 0-12.jpeg 0-5.jpeg 0-9.jpeg How to fix that? I was trying to sort them but no way: 1) Array.Sort(files, (f1, f2) => f1.Name.CompareTo(f2.Name)); 2) Array.Sort(files, (x, y) => StringComparer.OrdinalIgnoreCase.Compare(x.Name, y.Name)); 回答1: Alphabetically, the "wrong" order is in fact correct. If you want it

scandir() to sort by date modified

匿名 (未验证) 提交于 2019-12-03 02:18:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to make scandir(); function go beyond its written limits, I need more than the alpha sorting it currently supports. I need to sort the scandir(); results to be sorted by modification date. I've tried a few solutions I found here and some other solutions from different websites, but none worked for me, so I think it's reasonable for me to post here. What I've tried so far is this: function scan_dir($dir) { $files_array = scandir($dir); $img_array = array(); $img_dsort = array(); $final_array = array(); foreach($files_array as $file

Sorting data based on second column of a file

匿名 (未验证) 提交于 2019-12-03 02:16:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a file of two columns and n number of rows. column 1 contains names and column2 age . I want to sort the content of this file in ascending order based on the age (in second column). The result should display the name of the youngest person along with name and then second youngest person and so on... Any suggestions for a one liner shell or bash script. 回答1: You can use the sort command: sort -k2 -n yourfile For example: $ cat ages.txt Bob 12 Jane 48 Mark 3 Tashi 54 $ sort -k2 -n ages.txt Mark 3 Bob 12 Jane 48 Tashi 54 回答2: Solution:

php mongodb full-text search and sort

匿名 (未验证) 提交于 2019-12-03 02:16:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: i nead to make a search with full text index and this code work: $cursor=$collection->find(array('$text'=>(array('$search'=>$s))), array("score"=> array('$meta'=>"textScore")) ); i try to sort the cursor with: $cursor =$cursor->sort(array("score"=>1)); when i try to read var_dump($cursor->getNext()); i gave me this error Uncaught exception 'MongoCursorException' with message 'localhost:27017: Can't canonicalize query: BadValue can't have a non-$meta sort on a $meta projection' any idea? 回答1: You are attempting to sort on a meta field, not a

Error: x must be atomic for 'sort.list'

匿名 (未验证) 提交于 2019-12-03 02:16:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This is weird. I get this error Error in sort.list(y) : 'x' must be atomic for 'sort.list' Have you called 'sort' on a list? when I execute this code on a list cc3 <- as.data.frame(table(cc2)) What could possibly be wrong? this is a head of the list. head(cc2) V1 1: 174 2: 174 3: 211 4: 177106 5: 177106 6: 177106 Edit: When I run, str(cc2) I get this Classes ‘data.table’ and 'data.frame': 149706 obs. of 1 variable: $ V1:List of 149706 ..$ : Named chr "174" .. ..- attr(*, "names")= chr "V11" ..$ : Named chr "174" .. ..- attr(*, "names")= chr

How to sort an array containing class objects by a property value of a class instance? [duplicate]

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Possible Duplicate: How to sort an array of object by a specific field in C#? Given the following code: MyClass myClass; MyClassArray[] myClassArray = new MyClassArray[10]; for(int i; i < 10; i++;) { myClassArray[i] = new myClass(); myClassArray[i].Name = GenerateRandomName(); } The end result could for example look like this: myClassArray[0].Name //'John'; myClassArray[1].Name //'Jess'; myClassArray[2].Name //'James'; How would you sort the MyClassArray[] array according to the myClass.Name property alphabetically so the array will look

“unsupported collating sort order” when trying to read from Access using Jackcess (Java)

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm currently working on a Java application with the purpuose of reading a Microsoft Access file using Jackcess open source library. The Java application will later present the tables contained in the Access file. Here is my code so far: public class Test { public static void main(String[] args) throws IOException { File file = new File("\\\\student.local\\Files\\Home\\nat12mja\\Downloads\\Testdoc.accdb"); Database db = DatabaseBuilder.open(file); Table table = db.getTable("Table1"); for(Row row : table){ System.out.println(row.get("Field1")

DataGridView sort and e.g. BindingList&lt;T&gt; in .NET

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using a BindingList<T> in my Windows Forms that contains a list of " IComparable<Contact> " Contact-objects. Now I'd like the user to be able to sort by any column displayed in the grid. There is a way described on MSDN online which shows how to implement a custom collection based on BindingList<T> which allows sorting. But isn't there a Sort-event or something that could be caught in the DataGridView (or, even nicer, on the BindingSource) to sort the underlying collection using custom code? I don't really like the way described by MSDN.

How would you sort 1 million 32-bit integers in 2MB of RAM?

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Please, provide code examples in a language of your choice. Update : No constraints set on external storage. Example: Integers are received/sent via network. There is a sufficient space on local disk for intermediate results. 回答1: Split the problem into pieces small enough to fit into available memory, then use merge sort to combine them. 回答2: Sorting a million 32-bit integers in 2MB of RAM using Python by Guido van Rossum 回答3: 1 million 32-bit integers = 4 MB of memory. You should sort them using some algorithm that uses external storage.

Sort a list from another list IDs

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a list with some identifiers like this: List<long> docIds = new List<long>() { 6, 1, 4, 7, 2 }; Morover, I have another list of <T> items, which are represented by the ids described above. List<T> docs = GetDocsFromDb(...) I need to keep the same order in both collections, so that the items in List<T> must be in the same position than in the first one (due to search engine scoring reasons). And this process cannot be done in the GetDocsFromDb() function. If necessary, it's possible to change the second list into some other structure (