swap

How to “shuffle” an array? [duplicate]

有些话、适合烂在心里 提交于 2019-11-27 07:48:22
问题 This question already has an answer here: Random shuffling of an array 27 answers I am having a tough time trying to create a "shuffleDeck()" method. What I am trying to do is create a method that will take an array parameter (which will be the deck of cards) shuffle the cards, and return the shuffled array list. This is the code: class Card { int value; String suit; String name; public String toString() { return (name + " of " + suit); } } public class PickACard { public static void main(

Stepping through all permutations one swap at a time

◇◆丶佛笑我妖孽 提交于 2019-11-27 05:52:37
问题 Given a list of n distinct items, how can I step through each permutation of the items swapping just one pair of values at a time? (I assume it is possible, it certainly feels like it should be.) What I'm looking for is an iterator that yields the indices of the next pair of items to swap, such that if iterated n!-1 times it will step through the n! permutations of the list in some order. If iterating it once more would restore the list to its starting order that would be a bonus, but it isn

Can I tell Windows not to swap out a particular processes’ memory?

烂漫一生 提交于 2019-11-27 05:50:50
问题 Is there a way to tell Windows that it shouldn't swap out a particular processes' memory to disk? Its a .Net windows service with fairly large memory usage. I got lot of physical RAM but the OS seems to move part of the process memory to the pagefile anyway. 回答1: You can use VirtualLock to prevent memory from being paged to disk, but I really think you're better off letting the OS manage the system's memory. It's pretty good at it, and I wouldn't second guess why the OS was swapping things to

Replace Div with another Div

南笙酒味 提交于 2019-11-27 04:45:13
I have this thing I m trying to do. I have a main picture of a map and within that map there are regions. These regions have hot spots on them so you can click them and it will replace the whole map with only the region. (just a simple div swap). I need it as a div because in this div i have the hot spots listed. There are a total of 4 div s that I am going to need to do this with. If anyone could help me that would be awesome! So links that are listed in a table need to replace the image in a separate div . <tr class="thumb"></tr> <td>All Regions (shows main map) (link)</td> </tr> <tr class=

Why is this statement not working in java x ^= y ^= x ^= y;

人盡茶涼 提交于 2019-11-27 04:39:04
int x=1; int y=2; x ^= y ^= x ^= y; I am expecting the values to be swapped.But it gives x=0 and y=1. when i tried in C language it gives the correct result. Your statement is roughly equivalent to this expanded form: x = x ^ (y = y ^ (x = x ^ y)); Unlike in C, in Java the left operand of a binary operator is guaranteed to be evaluated before the right operand. Evaluation occurs as follows: x = x ^ (y = y ^ (x = x ^ y)) x = 1 ^ (y = 2 ^ (x = 1 ^ 2)) x = 1 ^ (y = 2 ^ (x = 3)) x = 1 ^ (y = 2 ^ 3) // x is set to 3 x = 1 ^ (y = 1) x = 1 ^ 1 // y is set to 1 x = 0 // x is set to 0 You could reverse

Swap two items in List<T>

為{幸葍}努か 提交于 2019-11-27 04:19:32
Is there a LINQ way to swap the position of two items inside a list<T> ? Jan Jongboom Check the answer from Marc from C#: Good/best implementation of Swap method . public static void Swap<T>(IList<T> list, int indexA, int indexB) { T tmp = list[indexA]; list[indexA] = list[indexB]; list[indexB] = tmp; } which can be linq-i-fied like public static IList<T> Swap<T>(this IList<T> list, int indexA, int indexB) { T tmp = list[indexA]; list[indexA] = list[indexB]; list[indexB] = tmp; return list; } var lst = new List<int>() { 8, 3, 2, 4 }; lst = lst.Swap(1, 2); Maybe someone will think of a clever

Overloading global swap for user-defined type

↘锁芯ラ 提交于 2019-11-27 01:55:17
问题 The C++ standard prohibits declaring types or defining anything in namespace std , but it does allow you to specialize standard STL templates for user-defined types. Usually, when I want to specialize std::swap for my own custom templated type, I just do: namespace std { template <class T> void swap(MyType<T>& t1, MyType<T>& t2) { t1.swap(t2); } } ...and that works out fine. But I'm not entirely sure if my usual practice is standard compliant. Am I doing this correctly? 回答1: What you have is

Is it possible to swap columns around in a data frame using R?

浪尽此生 提交于 2019-11-27 01:48:56
问题 I have three variables in a data frame and would like to swap the 4 columns around from "dam" "piglet" "fdate" "ssire" to "piglet" "ssire" "dam" "tdate" Is there any way I can do the swapping using R? Any help would be very much appreciated. Baz 回答1: dfrm <- dfrm[c("piglet", "ssire", "dam", "tdate")] OR: dfrm <- dfrm[ , c("piglet", "ssire", "dam", "tdate")] 回答2: d <- data.frame(a=1:3, b=11:13, c=21:23) d # a b c #1 1 11 21 #2 2 12 22 #3 3 13 23 d2 <- d[,c("b", "c", "a")] d2 # b c a #1 11 21 1

How to move specific item in array list to the first item

∥☆過路亽.° 提交于 2019-11-27 01:32:38
问题 For example : A list A B C D E Given C , Switch to C A B D E Notice that the array size will change, some items may removed in run times Collections.swap(url, url.indexOf(itemToMove), 0); This statement is not working because it output C B A D E not C A B D E , how to fix it? Thanks. 回答1: What you want is a very expensive operation in an ArrayList . It requires shifting every element between the beginning of the list and the location of C down by one. However, if you really want to do it: int

how to update swap values of two rows with single query

对着背影说爱祢 提交于 2019-11-27 01:23:04
问题 Is there a query with which i can exchange the values of two rows with single query? 回答1: you can see the solution in this article http://www.microshell.com/database/sql/swap-values-in-2-rows-sql/ look at the : The elegant way , make a join to get the data from the 2 rows to be swapped in 1 row, after that make an update is easy. example : UPDATE rules AS rule1 JOIN rules AS rule2 ON ( rule1.rule_id = 1 AND rule2.rule_id = 4 ) SET rule1.priority = rule2.priority, rule2.priority = rule1