sorting

Sort elements, but keep certain ones fixed

孤者浪人 提交于 2020-01-13 08:51:08
问题 The function template <typename Container, typename Comparator, typename Predicate> void sortButKeepSomeFixed (Container& c, const Comparator& comp, const Predicate& pred) is to sort the container c according to the ordering criterion comp , but those elements that satisfy pred shall remain fixed in their original positions after the sort (i.e. unaffected by the sort). I tried to adapt quick sort to fit this, but could not think of it. In the end, I decided to adapt the crude selection sort

Sort TreeView Automatically Upon Adding Nodes

て烟熏妆下的殇ゞ 提交于 2020-01-13 08:45:15
问题 Is there an easy way to add nodes to a WinForms .NET TreeView control where the new nodes being added are inserted at the correct index so the entire list of nodes is sorted alphabetically? Pretty much having the same result as TreeView.Sort() . I have a TreeView that continually grows to a couple hundred nodes. The user can view this TreeView in real time as it grows. I'd prefer to just insert the nodes at the correct index, rather than calling TreeView.Sort() each time after a node is added

Fast sorting in Haskell

跟風遠走 提交于 2020-01-13 08:44:32
问题 After reading Stack Overflow question Using vectors for performance improvement in Haskell describing a fast in-place quicksort in Haskell, I set myself two goals: Implementing the same algorithm with a median of three to avoid bad performances on pre-sorted vectors; Making a parallel version. Here is the result (some minor pieces have been left for simplicity): import qualified Data.Vector.Unboxed.Mutable as MV import qualified Data.Vector.Generic.Mutable as GM type Vector = MV.IOVector Int

Fast sorting in Haskell

早过忘川 提交于 2020-01-13 08:44:32
问题 After reading Stack Overflow question Using vectors for performance improvement in Haskell describing a fast in-place quicksort in Haskell, I set myself two goals: Implementing the same algorithm with a median of three to avoid bad performances on pre-sorted vectors; Making a parallel version. Here is the result (some minor pieces have been left for simplicity): import qualified Data.Vector.Unboxed.Mutable as MV import qualified Data.Vector.Generic.Mutable as GM type Vector = MV.IOVector Int

sorting std::lists using std::sort [duplicate]

六月ゝ 毕业季﹏ 提交于 2020-01-13 07:52:11
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Sort list using stl sort function why only std::list::sort()? My question is can we sort two std::lists using std::sort function? I have 2 string lists std::list<std::string>list1, list2; .....//entering values to list std::sort(list1.begin(), list1.end()); std::sort(list2.begin(), list2.end()); while i am sorting these lists i am getting error. I tried with std::vector, at this time the sort works. The error is

List custom post type by custom field date

那年仲夏 提交于 2020-01-13 05:47:07
问题 I'm working with Wordpress and WP-Types plugin and need to sort CPT by a custom field date. This work fine: $args = array( 'post_type' => 'parties', 'paged' => $paged, 'meta_key' => 'wpcf-parties_date', 'orderby' => 'meta_value', 'order' => 'DESC', ); The orderby works perfect. On the Database the value of the field date 'wpcf-parties_date' is store in this way ex: 1349481600 . I have two templates where i need to show past and upcoming Posts. My question is how can i display only the future

Sort week day texts

对着背影说爱祢 提交于 2020-01-13 05:38:19
问题 I have list ["Tue", "Wed", "Mon", "Thu", "Fri"] as list, I want to make it as ["Mon", "Tue", "Wed", "Thu", "Fri"] . How to sort this? 回答1: Not very efficient, but if you have a list of the order they're supposed to be in... >>> m = ["Mon", "Tue", "Wed", "Thu", "Fri"] >>> n = ["Tue", "Wed", "Mon", "Thu", "Fri", "Tue", "Mon", "Fri"] >>> sorted(n, key=m.index) ['Mon', 'Mon', 'Tue', 'Tue', 'Wed', 'Thu', 'Fri', 'Fri'] Note, this will throw an exception if a certain value is present in n that isn't

Sort week day texts

萝らか妹 提交于 2020-01-13 05:38:19
问题 I have list ["Tue", "Wed", "Mon", "Thu", "Fri"] as list, I want to make it as ["Mon", "Tue", "Wed", "Thu", "Fri"] . How to sort this? 回答1: Not very efficient, but if you have a list of the order they're supposed to be in... >>> m = ["Mon", "Tue", "Wed", "Thu", "Fri"] >>> n = ["Tue", "Wed", "Mon", "Thu", "Fri", "Tue", "Mon", "Fri"] >>> sorted(n, key=m.index) ['Mon', 'Mon', 'Tue', 'Tue', 'Wed', 'Thu', 'Fri', 'Fri'] Note, this will throw an exception if a certain value is present in n that isn't

Mongo DB duplication issue while using sorting with limit and skip in aggregation

放肆的年华 提交于 2020-01-13 04:26:33
问题 Facing an issue of duplicate records while fetching record by sorting with skip and limit: Collection Data: { "_id" : ObjectId("594b507c9b9469ec9da6a78b"), "name" : "F", "percentage" : 60.0, "weightedFilter" : 2.0, "like" : 1.0, "attraction" : 1.0 } { "_id" : ObjectId("594b507c9b9469ec9da6a78c"), "name" : "I", "percentage" : 80.0, "weightedFilter" : 0.0, "like" : 1.0, "attraction" : 1.0 } { "_id" : ObjectId("594b507c9b9469ec9da6a78d"), "name" : "J", "percentage" : 80.0, "weightedFilter" : 1.0

Sorting the content of a dictionary by the value and by the key

对着背影说爱祢 提交于 2020-01-13 03:49:46
问题 Sorting the content of a dictonary by the value has been throughly described already, so it can be acheived by something like this: d={'d':1,'b':2,'c':2,'a':3} sorted_res_1= sorted(d.items(), key=lambda x: x[1]) # or from operator import itemgetter sorted_res_2 = sorted(d.items(), key=itemgetter(1)) My question is, what would be the best way to acheive the following output: [('d', 1), ('b', 2), ('c', 2), ('a', 3)] instead of [('d', 1), ('c', 2), ('b', 2), ('a', 3)] so that the tuples are