Questions tagged [sorting]

17691 questions
0

votes
0

answer
4

Views

Core Data extension to sort entities

The bottom line is to write an extension that sorts an array of NSManagedObjects by dateCreated. Or, to go from this: let materialArray = (Array(quote.materials!) as? [Materials])?.sorted(by: { $0.dateCreated?.compare($1.dateCreated!) == .orderedDescending }) to this: let materialArray = (Array(quot...
squarehippo10
1

votes
2

answer
368

Views

Excel Sorting “mixed data”

I have 3 columns of data that need sorting into a specific order. The column to sort on are alpha numberics but contain letters and numbers. The best I can do using the standard Excel sort function on the ribbon bar is: Ideally the output should be: AS you can see the Excel sort function isn't doing...
Jeff Haynes
1

votes
2

answer
534

Views

How to sort NSArray of custom objects by a specific property in descending order?

How do I make this piece of code to order in descending order. This code always gives me the array in ascending order: NSArray *sortedProductsByStyle = [unsortedProducts sortedArrayUsingComparator: ^(Product *p1, Product *p2) { return [p1.productStyle compare:p2.productStyle options:NSNumericSearch]...
Renexandro
1

votes
5

answer
168

Views

About sorting array list

I am trying to ensure that the objects i insert in productDatabase have not been already inserted and that i sort my arraylist using method sortData but without using any comparators in method sortData public class Application { public static void main(String[] args) { Product p = new Product(15,"t...
CurrentLer
1

votes
2

answer
7.4k

Views

How to sort a 2d array according to the second column using stl sort function?

How to sort a 2d array according to the second column using stl sort function ? For eg If we have an array a[5][2] and we want to to sort according to the ar[i][1] entry , how do we do it using the stl sort function. I understand we have to use a boolean function to pass as the third parameter but I...
Anmol Sood
1

votes
1

answer
1.3k

Views

Using factor with levels gives me NA

there's something I cannot figure out here is my data set Proband Lauf Interleukin Ansatz Zeitpunkt 1 3 2 IFNy stim ZP21 2 3 2 iL2 stim ZP4 3 3 2 iL2 stim ZP14 4 5 3 iL2 stim ZP...
newbymedicalstats
1

votes
1

answer
1k

Views

Insertion Sort algorithm ignoring first element

I am implementing a simple Insertion Sort in C++ shown below: void insertion_sort(int a[], int size) { int temp; for (int i = 2; i < size; i++) { temp = a[i]; int j = i - 1; while (j > 0 && a[j] > temp) { a[j + 1] = a[j]; j--; } a[j + 1] = temp; print_array(a, size); } cout = 0 then, Original array:...
user3420507
0

votes
0

answer
16

Views

How to Print Possible permutations of the Array length in java

I'm working on task in which i have to show the possible permutations of the length of array. I've tried some tricks but it's still giving the list of many outputs, and in the end my project get crash. I've tried mathematically and i got answer "39916800. For example: For input array [3,2,1,4,6], t...
Umer Waqas
1

votes
1

answer
44

Views

How to rearrange a list of lines in all possible ways and write those to files via bash script?

I did some measurements and got a list of 132 lines in a csv file. The data looks like this: 13,5;26;10;45,2;48,3 13,5;26;15;49,7;52,9 13,5;26;20;54,8;58,0 I would like to write all possible combinations of those lines into files, from outputs of a single line to a maximum of 44 lines. The order in...
Markus Hern
1

votes
2

answer
25

Views

Merge K sorted arrays of Length N

This is the problem as stated in the book: Suppose you are given K sorted arrays each with n elements, and you want to combine them into a single array of kn elements. You use the following approach: first merge the first and second arrays, then merge the resulting array with the third array, then t...
DCS
1

votes
1

answer
103

Views

VisualBasic order List by Property as String

I've got an List of an Custom Class and want to order this List by an Property, but I only have the String of the Property name, becasue I recive this from an javascript. I tried this with System.Reflection, but it seem, that it isn't working: Dim l As List(Of ActionElement) = New List(Of ActionElem...
Cedric Krause
1

votes
2

answer
214

Views

sort fields within a line

input: 87 6,1,9,13 3 9,4,14,35,38,13 31 3,1,6,5 (i.e. a tab-delimited column where the second field is a comma-delimited list of unordered integers.) desired output: 87 1,6,9,13 3 4,9,13,14,35,38 31 1,3,5,6 Goal: for each line separately, sort the comma-separated list appearing...
cmo
1

votes
2

answer
792

Views

Sort in GWBASIC

I work with GWBASIC but unable to figure out a simple way to sort (numbers) I only have 4 numbers to deal with (range 150-200) After some calculations I get these 4 numbers and I need to have them sorted in ascending order to go to the next step.Right now I do this by hand looking at the output on...
Bugle24
1

votes
2

answer
88

Views

What is the lowest bound for the algorithm?

Let an algorithm which get unsorted array with the size of n. Let a number k
AlonAlon
1

votes
1

answer
685

Views

Sorting the results of _.countBy

I have a collection (Products) and I use _.countBy like this : var totalByBrand = _.countBy(result, "Brand"); and I have this result : { 'Brand 1 ' : 5, 'Brand 2 ' : 45, 'Brand 3 ' : 2, ... 'Brand 99 ' : 25 } I try to sort this result to obtain that : { 'Brand 3 ' : 2, 'Brand 1 ' : 5, 'Brand 99 ' :...
David Naoures
1

votes
4

answer
3.4k

Views

How do I convert a text file into a list then sort it with Python?

I have a text file with the following lyrics: 'First verse Im off till I'm off the island i'm riding like autoban on autopilot before I touch dirt I deal you all with kindness my natual persona much worse' I want to convert it to a list, then sort it alphabetically, but what I keep getting is: [[Fir...
MikeT
1

votes
7

answer
1.5k

Views

Java to sort list of custom object on the basis of string

class Person { private String name; private String profession; } profession has values: engineer Doctor Teacher student I have list of person and want to sort it on the basis of Profession. engineer comes first then Doctor and then Teacher and then student. Is it possible to sort it with comparabl...
user3586231
1

votes
2

answer
493

Views

Sort Array of Objects by Date

I am using jLinq to query an Array of Objects this is my Array of Objects: wo: [{ ID: 1, 'CreatedYM': '2015-Jun'}, { ID: 2, 'CreatedYM': '2014-May'}, { ID: 3, 'CreatedYM': '2015-Jan'}, { ID: 4, 'CreatedYM': '2015-Aug'}, { ID: 5, 'CreatedYM': '2014-Dec'}] this is my query: jlinq.from( wo ).group...
Lugarini
1

votes
2

answer
1.9k

Views

Is there an argsort function in java? [closed]

I'd like to use an argsort function on arrays or arraylist or an other data structure in Java but I didn't find in the documentation an argsort function. I know there is a sort method on the Collections class but there isn't any argsort method. Is there any class with an argsort method already imple...
fonfonx
1

votes
4

answer
643

Views

Partial Ordered Comparator to Total Ordered Comparator

First of all: this is not a duplicate of the question Partial Ordered Comparator but rather builds on it. My goal is to sort a list of objects (e.g. [2, "a", 1]) in-place such that after sorting no two integers are out of order. For this, I used the implementation in this answer with the following p...
blubb
1

votes
1

answer
418

Views

does a compound index in MongoDB improve multified match (not sorting)?

The documentation seems a bit unclear on that. 1)It clearly states that compound indexes DO improve performance of multi-field SORTING (order and direction dependant). 2) There is one phrase which makes me think it will also improve multi field MACH (sql analogy: where a=1 and b=2 and c
user1312695
1

votes
2

answer
2.4k

Views

Java sort a Hashmap on Value

Learning Java as I go (Python background). Simple word count program in Java 7 code (can not use J8!). I have a hash map of word:count pairs. Now I need to sort on count (decreasing order), and break ties with using word in alphabetical order. Have read s/o and I tried a treemap but it does not se...
Max Wen
1

votes
1

answer
27

Views

How to sort by a formule in Mysql [closed]

I have a field named count and it has values like 10-3 , now I want to sort by finding 3/10 in all rows and sort by that . Is it possible in mysql ?
Jafar rezaei
1

votes
1

answer
129

Views

RuleBasedCollator not working on Android?

I try sort string with RuleBasedCollator on android. But no one example from https://developer.android.com/reference/java/text/RuleBasedCollator.html not working and throw exception on android 5. Caused by: java.text.ParseException: ucol_openRules failed: U_INVALID_FORMAT_ERROR (at offset -1) a...
andreich
1

votes
1

answer
2k

Views

JQuery Datatables sorting a select inside a column

I am using DataTables 1.10.12 and JQuery 1.12.3 I got a problem with sorting a column that have dropdown list inside it I am using the multi select filter. All is working fine, prob is that it can't sort the column including the select (that has selected="selected" option) probably because of the va...
Plotisateur
0

votes
0

answer
29

Views

How to correctly sort data returned from XML file?

I have this sample XML data 2017 7 27 THU Considerable clouds cloudy 18 5 2017 7 26 WED Cloudy with a thunderstorm thunderstorm 15 4 which i want sort in ascending order by the DATE after this ajax call function makeAjaxQueryWeather(){ var xhttp = new XMLHttpRequest(); xhttp.onreadystatechan...
user10482014
1

votes
2

answer
535

Views

Sorting list of strings using linq with custom sort

I am trying to sort a list of strings in an order that is pertinent to a sequence used in common revision history sequences. Some customers start with "-", or "New", or a few other specific codes, and I can use LINQ to define a custom sort order. However, after a drawing has been revised from Rev A...
AuLion
0

votes
1

answer
18

Views

in C++ using visual studio how can I create 3 functions one to read a file, one to sort a file, and one to output the sorted file?

I'm trying to finish an assignment. which is a program that reads sales data from a text file, sorts the data and outputs the sorted data to a second file. The input file is a comma-seperated value file (CSV), with the first item being the number of sales data items to be processed, followed by the...
CAP_BLUE
1

votes
2

answer
338

Views

Generic function to sort array of class by properties

I want to create a generic function to sort an array of classes based on a property passed. For example, I have these classes public class Car { var id: Int var manufacturer: String var variant: String init(id: Int, manufacturer: String, variant: String) { self.id = id self.manufacturer = manufactur...
avrospirit
9

votes
7

answer
254

Views

Sort objects in array with dynamic nested property keys

I'm trying to sort an array of nested objects. It's working with a static chosen key but I can't figure out how to get it dynamically. So far I've got this code sortBy = (isReverse=false) => { this.setState(prevState => ({ files: prevState.files.sort((a, b) => { const valueA = (((a || {})['general']...
Thore
0

votes
0

answer
10

Views

Rearrange the array of objects with id and parentid

I have two arrays. Both contain the objects with id and parentid values. The first one is ordered in the way that objects with parentid different than "parent" are situated right after the parent object with the corresponding id: const array1 = [ { id: "id1", parentId: "parent" }, { id: "id2", par...
Laszlo
1

votes
1

answer
32

Views

Having trouble sorting (list of tuples)

I'm trying to do a sort of shop like program, 5 items and it asks you the name of the product and price, i want to organize it by price descending. #initialise variables product1 = [] product2 = [] product3 = [] product4 = [] product5 = [] products = [] totalCost = 0.0 #input products and prices fun...
Kieran Laing
1

votes
1

answer
42

Views

Maximum VALUE of interval which overlaps

This is a follow up question to this question: Maximum no of overlaps of all time intervals This is a known question of finding the most overlapping intervals given pairs of begin and end times. I understand how to solve this question. I want to know how to solve a slight variation to the question....
Yonatan Nir
0

votes
2

answer
22

Views

C# how to make it so that a function that can sort strings or ints without overloading? [duplicate]

This question already has an answer here: creating a generic sort method 2 answers As the title says, I had to write some code to sort either array/list of strings or integers. My OOP knowledge is really rusty since I haven't used C#/Java for a long while. Is there a way to make it so I just need...
l337h4x0r
0

votes
1

answer
16

Views

Getting highest date from array of dates before 1970

Why isn't my code working? I thought once I used getTime() on the dates instead of trying to compare the dates it would work but it does not. Please help. Also I realize there is now way this example could be equal but for my actual project it can be so please don't exempt from any answers. Thank Yo...
Harper Creek
0

votes
5

answer
46

Views

JS - Do sort in an array of strings as dates

I have the following array: let datas = ["nov/2018", "set/2018", "jan/2019", "dez/2018", "out/2018"] when I execute datas.sort() he orders by alphabetical order, however, I must order first by the year and then by alphabetical order. ["dez/2018", "jan/2019", "nov/2018", "out/2018", "set/2018"] Test...
0

votes
1

answer
22

Views

Python Pandas: Group files in a directory by similar filenames and concatenate dataframes in a specific order

My goal is to group .csv files in a directory by shared characteristics in the file name. My directory contains files with names: After_Source1_Receiver1.csv After_Source1_Receiver2.csv Before_Source1_Receiver1.csv Before_Source1_Receiver2.csv During1_Source1_Receiver1.csv During1_Source1_Receiver2....
Colton Medler
1

votes
2

answer
267

Views

Read text file, break each line into separate arrays and sort in C

I am trying to write a program that reads a text file and breaks each line into separate arrays so they can be sorted by date and name. I am still having trouble getting the 'sort by date' function to work/display properly, which is why I haven't attempted the sort by name function yet. I seem to be...
codeRed
1

votes
1

answer
649

Views

Python lambda function to sort list of tuples

Initially, a list of tuples is sorted by their second value and their third value. tlist = [('a', 1, 14), ('a', 1, 16), ('b', 1, 22), ('a', 2, 1), ('c', 2, 9), ('d', 2, 11), ('d', 2, 12)] Trying to sort this list of tuples by their second value, reverse by their third value; that is, want the outp...
nk-fford
0

votes
0

answer
7

Views

How sort from a incoming iterator/generator in rust

I'm building a generic interface similar to generators that stream data from a stream to another, to eventually do things like: file |> toCsv |> filter |> sort |> filter... Now, I know how sort a vector/slice, but how sort form a incoming stream/iterator without put all in a vector? alike: stream.it...
mamcx

View additional questions