FAQ Database Discussion Community


Update and sort Qt ComboBoxes alphabetically

c++,qt,sorting,combobox
I want to write a program, working like a little navigation system uisng the Qt framework, but i still am very new to it. I created a dialog with two Comboboxes. Each combobox contains all "citynames". At the initialization the content of both boxes is sorted alphabetically. If a name...

Sorted List for Doubly Linked List

python,list,sorting,doubly-linked-list
I have following 2 classes node and doublylinked list class DLLNode(object): def __Init__ (self, data, prev_node=None, next_node=None): self.data=data self.prev_node=prev_node self.next_node=next_node def __str__(self): return str(self.data) class DoublyLinkedList(object): def __init__(self, head=None, tail=None): self.head=head self.tail=tail self.size=0 def add_to_head(self, data): newNode = DLLNode(data) if self.head==None: self.head=self.tail=newNode self.head.prev_node=self.tail.next_node=None else: self.head.prev_node=newNode...

odd results from nested for loops javascript

javascript,arrays,sorting,object
I'm trying to check a submitted string against a letterset. If word_string = "GAR", this should return "GAR" because these letters appear in letterset. For some reason, some words appear correctly, and some appear with missing letters. For example, with word_string = "RAG", this returns "R". "FIG" returns "FG". letterset...

XSLT sort by attribute and attribute value (with exclude)

sorting,xslt,attributes,xslt-1.0,alphabetical
I have a following XML code: <module> <component> <output> <output-test> <exclude-output/> <orderEntry type="specific"/> <orderEntry type="other"/> <orderEntry type="module" module-name="module1"/> <orderEntry type="module" module-name="module3"/> <orderEntry type="module" module-name="module2"/> <orderEntry type="library" name="library1"/> <orderEntry type="library" name="library3"/> <orderEntry type="module" module-name="module4"/> <orderEntry...

NSTableView - how to get automatic and manual sorting working together?

osx,swift,cocoa,sorting,nstableview
I have a NSTableView in MyViewController and have an array controller bound to it. I want to be able to sort it by clicking the table column headers and it should also auto-sort. So for auto-sort I set the Sort Descriptors binding of my array controller in IB as following:...

Associative array not storing first result from SQL

php,mysql,arrays,sorting
I have a database in MySQL and I'm using this query to select certain rows from it using PHP: $q = "SELECT Number, Body FROM boxes WHERE Number BETWEEN '1' AND '4' ORDER BY Number ASC"; Then calling the query and initiating arrays: $r = $mysqli->query($q); $row = mysqli_fetch_array($r, MYSQLI_ASSOC);...

jQuery disable sort by mouse

jquery,sorting,jquery-ui-draggable
Is there a solution to disable ui sorting by mouse drag event in jQuery? I use the function sortable but I created arrows to short. I want to disable the regular mouse drag functionality. function moveUp(item) { var prev = item.prev(); if (prev.length == 0) return; prev.css('z-index', 999).css('position','relative').animate({ top: item.height()...

EXC_BAD_ACCESS error occurring when running recursive merge sort method in a thread

c++,multithreading,sorting,recursion
I'm having trouble with my C++ code in xCode. I've tried debugging and I can't fix it. I know it's roughly when my mergeSort() method calls my mergeNumbers() method. I know it's not the method itself because I've run the method without threading and it works just fine. It's when...

sorting an array in the same line as instantiation/initialization

java,arrays,sorting,initialization
If given an array of ints: int[] age = new int [] {32, 25, 56, 56, 12, 20, 22, 19, 54, 22}; Is there a way to sort(lowest-highest) in the same line as instantiation/initialization, so that the elements of age would be: 12, 19, 20, 22...?...

Improving a sort program's efficiency; displaying column sort % completion in terminal

python,perl,sorting,unix
I have a big pipe-delimited input file approx 6 million lines as below: 24|BBG000SJFVB0|EQ0000000009296012|OI SA-ADR|OIBR/C|US|ADR|Equity 16|BBG002PHVB83|EQ0000000022353186|BLOOM SELECT INCOME FUND|BLB-U|CT|Closed-End Fund|Equity -50|BBG000V0TN75|EQ0000000010271114|MECHEL-PREF SPON ADR|MTL/P|US|ADR|Equity 20|BBG002S0ZR60|EQ0000000022739316|DIVIDEND 15 SPLIT CORP II-RT|DF-R|CT|Closed-End Fund|Equity -20|BBG001R3LGM8|EQ0000000017879513|ING FLOATING RATE SENIOR LOA|ISL/U|CT|Closed-End Fund|Equity 0|BBG006M6SXL2|EQ0000000006846232|AA...

java 8 stream groupingBy sum of composite variable

java,sorting,java-8,grouping,java-stream
I have a class Something which contains a instance variable Anything. class Anything { private final int id; private final int noThings; public Anything(int id, int noThings) { this.id = id; this.noThings = noThings; } } class Something { private final int parentId; private final List<Anything> anythings; private int getParentId()...

How can I sort one array depending on another array?

php,arrays,sorting,multidimensional-array
I have two arrays stored in an array. They have the same number of values and are aligned: $matrix['label1'] $matrix['label2'] I want to apply alphabetical sorting to $matrix['label1'] and move the contents of $matrix['label1'] in the same pattern. Here is an example of input and output. $matrix['label1'] = ['b','c','a'] $matrix['label2']...

Which STL container(s)/algorithm(s) could I use to solve this?

c++,algorithm,sorting,stl,containers
I have an MFC project which, given an initial root path, iterates through every file, folder and subfolder, and subsequently displays each file to the user in a List Control. Since this can easily become a rather lengthy operation, I occasionally yield control to the operating system (via processing a...

Sorting vector of Pointers of Custom Class

c++,sorting,c++11,vector
I have vector<FPGA*> current_generation_, which I'd like to sort by FPGA member fitness_ using the sort_members function. Applicable code follows: bool sort_members (FPGA* fpga_first, FPGA* fpga_second) { return (fpga_first->fitness() < fpga_second->fitness()); }; fpga.hpp #include <vector> class FPGA { public: explicit FPGA(int input_gates, int output_gates, int normal_gates); const int fitness(); protected:...

Sorting array of objects using time and Angularjs

javascript,arrays,angularjs,sorting
I want to sort my array of objects in order from earliest to latest in time. I used the momentjs library to do this at first and it worked, but the method I was using is now deprecated. At first I tried making the input time into a standard time(ex:...

Sorting jQuery dataTables by class name when there is no type or value

javascript,jquery,sorting,jquery-datatables
I'm using DataTables: https://www.datatables.net/ Heres my HTML: <div class="dataTable_wrapper"> <table class="table table-striped table-bordered table-hover center" id="dataTables-example"> <thead> <tr> <th>ID</th> <th>Title</th> <th>Actions</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>title 1</td> <td><a href="./action-1"><span class="on"></span></a></td> </tr> <tr>...

Using linux sort on multiple files

linux,sorting
Is there a way I can run the following command with Linux for many files at once? $ sort -nr -k 2 file1 > file2 ...

Javascript sort array of objects in reverse chronological order

javascript,arrays,sorting
I have an array of objects which holds a list of jobs and I would like to sort them in reverse chronological order as they would appear on a resume for example. I came up with the below solution which 'seems' to work but I was wondering if there is...

Sort Array by Date and Size (Files)

java,arrays,sorting
I've got a method that returns to me a String[] of names of the Files of a current path, the thing I'm trying to do is make a method that returns to me this String[] of names but sorted by date, and sorted by size, I've almost done this, but...

sorting of month in matrix in R

r,sorting,matrix
I have a matrix in this format: year month Freq 1 2014 April 466 2 2015 April 59535 3 2014 August 10982 4 2015 August 0 5 2014 December 35881 6 2015 December 0 7 2014 February 17 8 2015 February 24258 9 2014 January 0 10 2015 January 22785...

Adding a new Worksheet in its Alphabetically correct position

excel,vba,sorting
I have a Workbook with a number of Worksheets, currently 6 but this will increase in the future. The Tabs / Worksheet names are in Alphabetical order, with a "Template" sheet at the end. I am cloning that Template sheet & creating a new Worksheet with the name specified by...

Java - order things in an arraylist according to an atribute

java,sorting,arraylist
Hi, i have an arraylist, lets call it "callcenterList" in that arraylist i will add objects of the "Call" class. The "Call" objects have different atributes, some of them are "Status", "Month" and "Day" (Month and day when the call was received and the Status of it). The status could...

Sort multiple columns of Excel in VBA given the top-left and lowest-right cell

excel,vba,excel-vba,sorting
I am trying to sort these three columns (Sort By Col-2) in excel using VBA. Top-left (Row number and Column number e.g. 1,1) and lowest-right cell (Row number and Column number e.g. 9,3) are known. Every cell contains the values of String type. Input: Col-1 Col-2 Col-3 P1 I1 XYZ...

Given an array/object of datetimes, how can I return an array/object of the times sorted by hour and times sorted by days of the week

php,arrays,sorting,datetime,laravel
PHP/Laravel, I'm getting an array of objects that includes date times for each record. I need to generate analytics on objects on an hourly basis of a day and daily basis of a week. So for example: For a date range of 1/1/2015 - 1/10/2015 I return 100 records all...

Sort 2 Arrays in Reverse in C#

c#,arrays,sorting
I am working on a project where i need to take in 2 Arrays and sort to print them out in decending order. this is what i have now: string[] nPlayer = {"aaa", "bbb", "ccc", "ddd", "eee"} int[] nScore = {555, 444, 333, 222, 111} public void Print() { Array.Sort(nScore,...

Sorting a dictionary value which is a list of objects by given fields

c#,linq,sorting,dictionary
I have a SortedDictionary whose value is a List of objects. I want to sort the value(the list) of each key by a given property of the object. In the current situation, I need to sort the list first by objects's lastname, then by firstname. I tried LINQ and it...

Sort four (4) javascript arrays with 10 objects each by a value

javascript,sorting
model w/ sample data => [{ date: '13413413', name: 'asdfasdf', other: 'kjh' }] getJSON returns 4 arrays of 10 model objects each. array1 = 10 of resultsObj sorted by date from newest to oldest array2 = 10 of resultsObj sorted by date from newest to oldest array3 = 10 of...

Wrong column filtering for date column

javascript,sorting,formatting,filtering,tablesorter
I use tablesorter to sort columns. But I found the following issue: As you can see the second row doesn't have 16. This table also have the external search field and search result equals 1 if I type 16, thus second row doesn't show. But it lools like a tablesorter...

Sort array by keys in custom order

php,arrays,sorting
I have the following multidimensional array Array ( [June 2015] => Array ( [LOW] => Array ( [0] => 160.50 ) [MEDIUM] => Array ( [0] => 0.00 ) [HIGH] => Array ( [0] => 60.80 ) ) [July 2015] => Array ( [MEDIUM] => Array ( [0] => 226.00...

Issue with sorting algorithm - VB

vb.net,algorithm,sorting
I've been struggling with this algorithm below. It is supposed to loas the times inputted from eight textboxes into an array (txtTD1, etc). It then sorts them, and assigns each a numeric rank, which is displayed to the user (in txtR1, etc). Dim timeArr(0 To 7) As String timeArr(0) =...

Sorting or Arranging an Array with a standard array values

javascript,arrays,algorithm,sorting
I want to sort a dyanamic javascript array which is being fetched everytime from Database. The condition is i want to sort it according to the values stored in a particular order in a standard pre-defined array. Lets say my Dyanamic array is like : var dbArray = ['Apple','Banana','Mango','Apple','Mango','Mango','Apple']; and...

Sort an PowerShell array according to a part of content in each element

arrays,sorting,powershell,powershell-v2.0,powershell-v3.0
I am working with a powershell script where I have an array containing following data. Each row below is an element in the array. Each element has two parts seperated by "/" a number (can be 1-12 digits) and a date time. I need to sort the array according to...

Javascript Sorting Array of Objects [duplicate]

javascript,arrays,sorting,object
This question already has an answer here: Sorting an array of JavaScript objects 14 answers (Please excuse any errors - this is my first post and I am also relatively new to Javascript) I'm trying to sort an array of objects by a specific property value in Javascript. I...

SilverStripe 3: Loop greatgrandchildren pages WITH OUT grouping by parent

sorting,loops,templates,silverstripe
In my template I'm looping my child pages as 2 separate lists and then their grandchild pages under these. But I want these greatgrandchild pages to be sorted as an entire list and not divided / grouped by their parents. Simply loop after loop does not work as all greatgrandchild...

Sorting networks costs and delay

sorting,sorting-network
From what I red I could not figure it out how the cost and delay are calculated. Cost -The number of sticks or compare-exchange blocks. Delay -the number of compare-exchanges in sequence. I have posted my example bellow ...

Sorting in Ruby on rails

ruby-on-rails,json,sorting
I'm very new to Ruby on rails. I try to edit the following api. I want to sorting "can_go" which is true are shown at the top of list. I added this row before sending data, but the result is still order by "user_id". user_infos.sort { |a, b| - (a['can_go']<=>b['can_go'])...

Sort arrayList based on both date and ID

java,sorting
i want to sort the list of task,first by date and then by taskID below is the code ArrayList<fullist> taskdet = new ArrayList<fullist>(); public static class fullist { public int date; public int id; public fullist(int id, int date) { this.date = date; this.id = id; } } i used...

Reading and listing objects in the order they appear in the source file in R

r,sorting,object,ls
I have a file with list of paths to URLs and and files that resembles the extract bellow: urls_queries_files.R url_some_dta <- "url_goes_here" backup_some_dta <- "path to the backup rds file goes here" url_exotic_dta <- "another_url" backup_exotic_dta <- "some backup rds file" url_mysterious_dta <- "url goes here" backup_mysterious_dta <- "backup rds...

Sorting entire csv by frequency of occurence in one column

python,sorting,csv,pandas,frequency
I have a large csv file, which is a log of caller data. A short snippet of my file: CompanyName High Priority QualityIssue Customer1 Yes User Customer1 Yes User Customer2 No User Customer3 No Equipment Customer1 No Neither Customer3 No User Customer3 Yes User Customer3 Yes Equipment Customer4 No User...

WPF MVVM custom Sorting issue

c#,asp.net,wpf,sorting,mvvm
I am trying to create custom sorting WPF Data Grid. I have did database call on every sorting. I have used MVVM for this. Issue is I am always getting Sort Direction of column always null on sorting event when I make DB Call. If I remove UpdateData method from...

MongoDB custom sorting with the other values?

javascript,mongodb,sorting
I'd like to be able to sort this collection according to the following attributes of each item. var distance1 = { velocity : 100, time: 20, rank: time*velocity}; var distance2 = { velocity : 50, time: 25, rank: time*velocity}; var distance3 = { velocity : 300, time: 10, rank: time*velocity};...

Sort a string alphabetically using a function

javascript,sorting
Imagine you were given a string and you had to sort that string alphabetically using a function. Example: sortAlphabets( 'drpoklj' ); //=> returns 'djklopr' What would be the best way to do this?...

Formatting a Pivot Table in Python

python,sorting,pandas,format,dataframes
I am trying to reformat a table based on counts in different columns. df = pd.DataFrame({'Number': [1, 2, 3, 4, 5], 'X' : ['X1', 'X2', 'X3', 'X3', 'X3'], 'Y' : ['Y2','Y1','Y1','Y1', 'Y2'], 'Z' : ['Z3','Z1','Z1','Z2','Z1']}) Number X Y Z 0 1 X1 Y2 Z3 1 2 X2 Y1 Z1 2...

Sort my str_repeat

php,sorting,repeat,alphabetical
I have spent the past 6 hours trying to figure out how to sort my str_repeat alphabetically based on game. So far all I have been able to do is get it to show the first one in the list as if it was alphabetized. Here is my code. $result...

How to swap two dates in swift

arrays,swift,sorting,swap
Trying to swap two dates in Swift. It currently gives me an error saying: Cannot subscript a value of type '[Mission]' with an index of type 'Int' func sort (mission: [Mission]) -> Bool { for (var i = 0; i < mission.count; i++) { println(mission[i].createdAt) if mission[i].createdAt.timeIntervalSince1970 > mission[i+1].createdAt.timeIntervalSince1970 {...

Can't sort array of structures alphabetically

c,arrays,sorting,struct,structure
I am trying to sort strings in an array of structures alphabetically then print, but my code doesn't work. I've been trying to figure out why for the past few hours, but can't figure it out. I'm sure its probably something super obvious, but I've only been programming for a...

Comparison method violates its general contract when sorting

java,sorting,comparison
I keep getting: Comparison method violates its general contract! Exception for the below compare function when I call Arrays.sort(ScreenItems) One assumption I have is that the ParseInt below is throwing an exception for the left object but not to the right object Could that be the case? public int compare(Object...

Sorting a HTML structure

javascript,html,sorting
Im trying to sort a div structure based on a paramter using a small javscript i found. It seems to not perform exactly as expected. I understand the sorting function is not parsing the values perfectly... This is the sorting logic is use... <script type="text/javascript"> // Sorting Logic $(function() {...

How can I tell how many times these nested statements will execute?

algorithm,sorting,big-o,time-complexity,complexity-theory
I have the following pseudocode: SelectionSort(A) n = A.length for j=1 to n-1 smallest = j for i=(j+1) to n if A[i] < A[smallest] smallest = i exchange A[j] with A[smallest] I think that the first for-loop test will execute n times, and the nested for-loop will execute 1 +...

Merge multiple lists based on List priority

java,sorting,collections,priority
I have couple of lists where each list has different priority. When i merge these lists i should get with height priority on top. Assume i have 3 lists and different objects value common in 3 lists should come first and then the top priority list should be appended vice...

elastic search sort in aggs by column

sorting,elasticsearch,group-by,order
I am trying to sort in elastic search in aggs, equivalent in mysql "ORDER BY Title ASC/DESC". Here is the index structure: 'body' => array( 'mappings' => array( 'test_type' => array( '_source' => array( 'enabled' => true ), 'properties' => array( 'ProductId' => array( 'type' => 'integer', 'index' => 'not_analyzed'...

Sum NA values in r

r,sorting,na
I am using a dataframe that has multiple NA values so I was thinking about sorting the attributes based on their NA values. I was trying to use a for loop and this is what I have so far: > data <- read.csv("C:/Users/Nikita/Desktop/first1k.csv") > for (i in 1:length(data) ) {...

Sort an array based on another array's values in PHP

php,arrays,sorting
I have an array with values as follows:- $Array1 = array("myfirst_value", "mysecond_value", "mythird_value"} Now for my another array, the listing comes in randomly as follows:- $Array2 = array ( [4] => myfirst_value [8] => myforth_value [21] => mysecond_value [7] => myfifth_value [17] => mysixth_value [20] => mythird_value [16] => myseventh_value...

File Handling and making directories to match in bash

bash,shell,sorting,matching,file-handling
I have these files: File_1.2.txt, File_1.5.txt, File_2.3.txt, and File_4.7.txt. I want to make directories for them and sort them into the directories, like below. Dir_001 -> File_1.2.txt File_1.5.txt Dir_002 -> File_1.2.txt File_2.3.txt Dir_003 -> File_2.3.txt Dir_004 -> File_4.7.txt Dir_005 -> File_1.5.txt Dir_007 -> File_4.7.txt So a directory is made for...

Macro - Multi Level sort by column name

excel,vba,sorting,excel-vba
I download a set of data from a program that i put into excel. From here, i would like to sort this data in 2 levels. I recorded a macro for this, which serves the basic purpose. The issue is that I would like the macro to search for the...

Sorting a list with dictionaries, django

python,django,list,sorting,dictionary
myFrom two models in django i have created a list of dictionarys where each dictonary is a row in a table I show in the client. I would like to be able to sort this list for each of the different "columns". objdict = [] mydict = { 'thing1': model1.val1,...

How to sort multidimentional array

c++,c,sorting,for-loop
New to coding ! After many attempts to use sort without success, here my actual code : #include <algorithm> #define N 5 int a[N] = { 3, 6, 2, 4, 1 }; int b[N] = { 6, 3, 1, 2, 9 }; int c[N][3]; for ( size_t i = 0;...

How to sum columns in R according to categories in 2 different groups

r,sorting
I have the following dataset imported from excel via "readxl::read_excel" command: Municipality Production Type Atima 690 Reverification Atima 120 Reverification Atima 220 Reverification Comayagua 153 Initial Comayagua 193 Initial Comayagua 138 Initial Comayagua 307 Reverification Copán 179 Initial Copán 100 Initial Copán 236 Reverification Copán 141 Reverification Danlí 56 Reverification...

Does MongoDB find() query return documents sorted by creation time?

database,mongodb,sorting
I need documents sorted by creation time (from oldest to newest). Since ObjectID saves timestamp by default, we can use it to get documents sorted by creation time with CollectionName.find().sort({_id: 1}). Also, I noticed that regular CollectionName.find() query always returns the documents in same order as CollectionName.find().sort({_id: 1}). My question...

Sort List of Numbers according to Custom Number Sequence

list,python-2.7,sorting
Question :A set of numbers will be passed as input. Also the redefined relationship of the digits 0-9 in ascending order will be passed as input. Based on the redefined relationship, the set of numbers must be listed in ascending order. Input Format: The first line will contain the the...

Emberjs advanced sort hasMany association as a computed property

sorting,ember.js,has-many,computed-properties
I have asked a variant of this question here. But basically I need to create a computed property that operated on a hasMany association. I need to do sorting similar to the javascript sort function; where I can do something like files = ["File 5", "File 1", "File 3", "File...

How do I remove duplicate objects in an array by field in Javascript?

javascript,arrays,sorting,object
I have an array of objects: [{ id: 1, name: 'kitten' }, { id: 2, name: 'kitten' },{ id: 3, name: 'cat }] How do I remove the second kitten? Sorting into an array of names doesn't work, because I can't know if I am deleting id 1 or or...

java - Is JavaFX SortedList stable?

sorting,javafx
Let's say I want to sort a list twice, using different comparators each, with the first comparator taking precedence over the second. Is it OK to simply call the SortedList constructor twice, with one call for each comparator? To clarify why I want to do this, let's say I have...

Read words/phrases from a file, make distinct, and write out to another file, in Java

java,file,sorting,distinct-values
I have a text file with a word or phrase on each line. How do I: Read those phrases into memory, Make distinct (eliminate duplicates), Sort alphabetically, Write the results back out to a file? StackOverflow has answers for similar Questions in other languages such as C, PHP, Python, Prolog,...

How to implement custom sort for koGrid?

javascript,sorting,knockout.js,typescript,kogrid
Data: 16.00 hours 19.99 hours 210.46 hours 262.54 hours 303.19 hours 55.95 hours 60.07 hours 64.07 hours 7.95 hours What I want: I need to allow sorting for this king of data in koGrid (default feature by clicking grid header, asc or desc sort). Problem: The data is string so...

How to implement mergeSort?

java,sorting,mergesort
I am trying to implement a recursive mergesort but the method is writting only zeros in the sorted vector. Here is my code. At the main function i just read the values to a vector and pass it as argument to mergesort. Any ideias of what i am doing wrong?...

sort runs out of memory

linux,sorting,memory,ram
I'm using a pipe including sort to merge multiple large textfiles and remove dupes. I don't have root permissions but the box isn't configured in any way to cut non root privileges further down than default debian jessie. The box has 32GB RAM and 16GB are in use. Regardless on...

SSRS re-sorts data meticulously sorted from the SQL query! Why?

sql-server,sql-server-2008,sorting,reporting-services
I'm writing up a report using SQL Server Reporting Service via Visual Studio 2008. I have a stored procedure on a SQL Server database that returns a list in which I need the entry with value "F" in colulmn [Column] to be always on top, as such: F A B...

Finding a number that is sum of two other numbers in a sorted array

arrays,sorting,find,sum
As it said in the topic, I have to check if there is a number that is the sum of two other numbers in a sorted array. In first part of the question (for a unsorted array) I wrote a solution, just doing 3 loops and checking all the combinations....

C++ lib in Python: custom sorting method

python,c++,sorting
I want to make a custom sorting method in C++ and import it in Python. I am not an expert in C++, here are implementation of "sort_counting" #include <iostream> #include <time.h> using namespace std; const int MAX = 30; class cSort { public: void sort( int* arr, int len )...

C# sorting arrays in ascending and descending order

c#,arrays,sorting
I'm having trouble writing a method that returns true if the elements of an array (numbers) are in sorted order, ascending or descending, and false, if they are not in any sorted order. I can return a correct boolean value if the array is ascending but i do not know...

Sort array of objects by subarray property value in javascript

javascript,arrays,sorting,sub-array
I have an array of JavaScript objects: var people = [ { "name": "Edward", "age": 100, "wallet": { "location": "home", "cash": 500 }, "bank": { "location": "bank street", "cash": 22100 } }, { "name": "Lisa", "age": 30, "wallet": { "location": "home", "cash": 20 }, "bank": { "location": "bank street", "cash":...

Sorting based on the rules set by a string variable

c++,qt,sorting,c++11
In my hypothetical app, I receive a list of hotels from the server. struct Hotel { std::string name; // e.g. Hilton, Ritz int stars; // In range [0..5], 0 stands for "unrated" int freeRoomCount; // Number of available rooms [0..N] int parkingPlacesAvailable; // Number of parking places availalble [0..M] }...

How do you build the example CUDA Thrust device sort?

c++,visual-studio-2010,sorting,cuda,thrust
I am trying to build and run the Thrust example code in Visual Studio 2010 with the latest version (7.0) of CUDA and the THURST install that comes with it. I cannot get the example code to build and run. By eliminating parts of the code, I found the problem...

Sublists of a list in java

java,list,sorting,arraylist,sublist
There are N buildings in a certain one-dimensional landscape. Each building has a height given by hi,i∈[1,N]. If you join K adjacent buildings, they will form a solid rectangle of area K×min(hi,hi+1,…,hi+k−1). Given N buildings, find the greatest such solid area formed by consecutive buildings. Input Format The first line...

12 Hour Clock Array Sort

php,arrays,sorting,time,clock
I have been searching on Google and couldn't find any solution to sort an array according to the 12 Hour clock format. I was able to sort the 24 hour clock by converting it to timestamps and then using krsort. But I am not sure how to sort a 12...

WPF Listview sort works only one time, and then nothing happen

c#,wpf,sorting,listview
I have a ListView in a WPF window, that I am trying to sort by clicking on the columns. To learn how to do this, I followed this link: http://www.wpf-tutorial.com/listview-control/listview-how-to-column-sorting/ I have created the method GridViewColumnHeader_Cick as follow: private void GridViewColumnHeader_Click(object sender, RoutedEventArgs e) { GridViewColumnHeader column = (sender as...

How to sort arrays with multiple items - Javascript

javascript,arrays,sorting
What I am trying to do is sort my three arrays (array1, array2, and array3) in order by their 0th term, to display the following. 1, banana, 2, grapes, 3, oranges. This is my code, but I can't figure out how to get it to sort the way I want....

Determine sorting algorithm from results

algorithm,sorting
I am now revising the sorting algorithms. Here is the question: It is given that this sorting algorithm is written in C, and treats 'a' and 'A' as equal, and after running this sorting algorithm, the results are as follows: 10000 random data -> 0.016 sec 100000 random data ->...

Elasticsearch - Order search results ASC

c#,sorting,elasticsearch,nest
having a problem with my elasticsearch. Setup: Having a Company-Class with the data field "companyName". My search shall search and response all companys with the searched term. If I try to sort via .Sort(x=> x.OnField(x => x.CompanyName).Descending()) The data aren't sorted rightly - reference stackOverflow I tried the given solution,...

Sort function giving floating point exception for a large input of 0's

c++,sorting,radix-sort,floating-point-exceptions
I have written a code for this problem: Given a list of non negative integers, arrange them such that they form the largest number. For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330. Note: The result may be very large, so you need to return...

Ranking with time weighting

python,algorithm,sorting,math
I am looking for a basic algorithm that gives more weigh to the recent reviews. So, the output value of the algorithm is mutable. For example, two reviews with exactly the same score, will have a different ranking based on the timestamp of the creation. Review_1 Score 10 creation 10/5/2014...

Find column with unique values move to the first column and sort worksheets

excel,vba,excel-vba,sorting
I have 2 worksheets with the same headers in different orders. Headers are I.D, Name, Department, Sales, Start date, End Date and a few others. What I am aiming to do is search through the workbooks in which the headers may be in different orders, find the column which has...

“sort not a function” error in angularjs only in google chrome

javascript,angularjs,google-chrome,sorting
I ran into this problem and am unable to figure out why and couldn't find any explanation on google. I have a $http.get method to retrieve some data from a url, on success i am sorting the response. But when I run the page on google chrome, I get the...

Sorting issue: i have li and i want it to sort by clicking on Asc and Desc

jquery,html,sorting
I want to sort list Ascending and Descending order. When i click on Ascending it will sort on Ascending order same as Descending order,Sorting should be apply by using jQuery or any other javascript library. Example code added on jsfiddle please click on link jsfiddle <p><a href="#" id="asc">Ascending</a> | <a...

sort list of objects in VB.NET by two elements

vb.net,list,sorting,object
I would like an extension of a question previously posted here Sort a List of Object in VB.NET In that question, the OP is asking how to sort a list of objects in VB.NET. His example uses something like passenger.name passenger.age passenger.surname And then, the accepted answer uses theList.Sort(Function(x, y)...

sorting vector of pointers by two parameters

c++,sorting,vector
I am trying to sort a vector of pointers to a class A using std::sort, but am having some difficulties. Imagine class A beings just a point, containing x and y coordinates. I want to sort the vector by y coordinates from biggest to lowest using some fixed offset value....

Efficiently sorting large arrays of people by their proximity to the user

javascript,arrays,sorting,mobile,latitude-longitude
So I'm trying to create a list of the 15 closest people in an array of varying sizes. The array will almost always be ~100 objects in size, but for the sake of testing, I'm trying to make it work with 10,000 (there may be need for the project to...

Change part of link with jquery

javascript,jquery,ruby-on-rails,ajax,sorting
I am using Ransack for sorting. I couldn't find way to change sorting links when search and sorting uses just ajax. So I am developing my own solution to change link and some other stuff. So far I have this Ruby <%= search_form_for @search, :class=>"search",:id=>"search-menio",:remote=>"true", url: advertisements_path, :method => :get...

Python custom sort

python,sorting,python-3.x
I am trying to sort a list using Python's sorted function. In Python 3 the cmp keyword argument was removed. Unfortunately it seems that I can not implement my algorithm using the key keyword argument since I both objects in order to compare the data. Example Sorted Data 59 59...

Sorting table created by PHP, can't use query to sort

php,mysql,sorting
I have a column I want to sort. Let me explain what the code does first. As you can see, there are three select statements for and from three different tables(table names are in the code). The first query selects data from the table whereby I assign the retrieved data...

Sorting imported text file?

python,sorting
So I've imported a text file into python. The file is a database storing users names and scores. It currently prints in pretty much the same format as the original file. I've split each line into two parts: name and score. I've managed to sort the data alphabetically, and am...

Algoritm to sort object by attribute value without allowing gaps or duplicates

python,sql,django,sorting,django-orm
I have a agenda with multiple dates, each date can contain 0 > ... items. Items can be sorted by position, positions should be Integer values without gaps and duplicates. class Item(models.Model): date = models.DateField() position = models.IntegerField() def move_to(position): qs = self.__class__.objects.filter(date=self.date) # if the position is taken, move...

Should checking loop conditions be counted towards total number of comparisons?

c++,algorithm,sorting,c++11
I have implemented three different sorting algorithms and now I want to confirm that my approach of counting the total number of comparisons is correct. In my mind, the number of comparisons shouldn't be tied to the conditional branches because if the condition isn't met, the comparison was still made...

How sorting parts of array my cause the whole array to be sorted

arrays,sorting
Recently i come across this problem and i couldn't find a solution for it, the problem is there is a array of numbers (N number) and we want to sort them, but we sort them in the way that shows in the picture: First Sort from 1 to K+L then...

WPF Listbox Collection custom sort

wpf,sorting,listbox,compare,collectionview
I have a listbox DropPrice MyPrice Price1 Price2 I want to sort it like this Price1 Price2 DropPrice MyPrice I mean, if there's an item that starts with the sequence "price", it gets priority, else the smallest string should get the priority. My source code: var lcv = (ListCollectionView)(CollectionViewSource.GetDefaultView(_itemsSource)); var...

Freeing array of dynamic strings / lines in C

c,string,sorting,malloc,free
I am writing a program that is sorting the lines from the input text file. It does its job, however I get memory leaks using valgrind. #include <stdio.h> #include <stdlib.h> #include <string.h> char* getline(FILE * infile) { int size = 1024; char * line = (char*)malloc(size); int temp; int i=0;...

How to sort the cards in each hand from the card values first and then the suits in C?

c,sorting
I want to sort the 5 cards from each hand, by sorting by the card value first (from Ace to King) and then the card suit (from Hearts, then Diamonds, then Clubs and lastly Spades), but it doesn't work. How would you be able to do it successfully? code: #include...

How to sort a variable-length string array with radix sort?

string,algorithm,sorting,radix-sort
I know that radix sort can sort same-length string arrays, but is it possible to do so with variable-length strings. If it is, what is the C-family code or pseudo-code to implement this? It might not a be fast algorithm for variable-length strings, but it is easy to implement radix...

Sort when values are None or empty strings python

python,list,sorting,null
I have a list with dictionaries in which I sort them on different values. I'm doing it with these lines of code: def orderBy(self, col, dir, objlist): if dir == 'asc': sorted_objects = sorted(objlist, key=lambda k: k[col]) else: sorted_objects = sorted(objlist, key=lambda k: k[col], reverse=True) return sorted_objects Now the problem...