swap Questions

8

Solved

As we all know, the pythonic way to swap the values of two items a and b is a, b = b, a and it should be equivalent to b, a = a, b However, today when I was working on some code, I accidentally f...
Ecotype asked 27/6, 2021 at 15:36

6

Solved

The problem I am trying to address arises with making containers such as an std::vector of objects that contain reference and const data members: struct Foo; struct Bar { Bar (Foo & foo, int...
Riha asked 28/9, 2011 at 8:52

3

I saw this question - What's the difference between "virtual memory" and "swap space"? Here it is mentioned that virtual memory = RAM space + disk space - which the process...
Shulamith asked 14/1, 2015 at 6:38

16

How can I swap two characters in a String? For example, "abcde" will become "bacde".
Mallemuck asked 5/6, 2009 at 14:35

13

Solved

I am wondering if there is a more efficient way of swapping two elements in an Array, than doing something like this: String temp = arr[1]; arr[1] = arr[2]; arr[2] = temp; Well, this is obviousl...
Understrapper asked 7/12, 2012 at 15:38

5

Solved

Is it possible to swap elements like in python? a,b = b,a or do we have to use: temp = a a = b b = temp
Bag asked 25/7, 2016 at 15:7

5

This is my swap function: template <typename t> void swap (t& x, t& y) { t temp = x; x = y; y = temp; return; } And this is my function (on a side note v stores strings) call t...
Everest asked 3/6, 2011 at 8:39

7

I have an array of int containing some values starting from index 0. I want to swap two values, for example, the value of index 0 should be swapped with the value of index 1. How can I do this in t...
Etrem asked 3/5, 2017 at 11:41

2

So I have edited it some and am getting almost exactly what I want. The only problem I am having now is that I am getting a line of output that I don't want. I feel like the fix here is simple but ...
Dislimn asked 6/3, 2021 at 20:38

4

Solved

I'm trying to swap the rows within the same DataFrame in pandas. I've tried running a = pd.DataFrame(data = [[1,2],[3,4]], index=range(2), columns = ['A', 'B']) b, c = a.iloc[0], a.iloc[1] a.iloc...
Caraviello asked 23/10, 2017 at 13:47

9

Solved

I am trying to swap every pair of values in my array using for and yield and so far I am very unsuccessful. What I have tried is as follows: val a = Array(1,2,3,4,5) //What I want is Array(2,1,4,3...
Polyadelphous asked 14/4, 2012 at 23:59

5

Solved

I have a list of tuples like this: [('foo','bar'),('foo1','bar1'),('foofoo','barbar')] What is the fastest way in python (running on a very low cpu/ram machine) to swap values like this... [('bar'...
Subfamily asked 14/11, 2012 at 18:19

4

Solved

STL implements a generic std::swap function to swap 2 values. It can be presented in the following way: template <class T> void swap (T& a, T& b) { T c(std::move(a)); a=std::move(b...
Rotter asked 17/8, 2013 at 9:52

3

Solved

I have a tensor of shape (30, 116, 10), and I want to swap the first two dimensions, so that I have a tensor of shape (116, 30, 10) I saw that numpy as such a function implemented (np.swapaxes) an...
Mystic asked 5/7, 2016 at 20:31

6

Solved

i have heard from a friend of mine that the best algorithm for swapping is " (a^=b^=a^=b)" where a and b are two integers to be swapped. but when i applied this using c language it resulted in cra...
Guibert asked 13/3, 2010 at 5:22

7

Solved

I want to maintain order of the elements being added in a list. So, I used a LinkedList in Java. Now I want to be able to swap two elements in the linked list. First of all, I cannot find an eleme...
Misspell asked 15/5, 2010 at 8:21

5

Solved

I have some bytearray with length of 2*n: a1 a2 b1 b2 c1 c2 I need to switch bytes endian in each 2-byte word, and make: a2 a1 b2 b1 c2 c1 Now I use next approach but it is very slow for my t...
Occupant asked 19/3, 2016 at 0:12

7

Solved

What are the differences between Swapping and Paging with reference to Process Memory Management ? Also guide me to the tutorials if any where I could get more information.
Cuevas asked 11/12, 2010 at 4:48

3

I have the following problem. I have two directories which I'll refer to as dir1 and dir2. They are both populated with both files and subdirectories. They are both on the same filesystem. The cont...
Bewitch asked 14/6, 2013 at 16:37

22

Solved

Can I easily swap two elements with jQuery? I'm looking to do this with one line if possible. I have a select element and I have two buttons to move up or down the options, and I already have the...
Eckmann asked 30/3, 2009 at 17:57

5

I have the following code: MyObject.prototype.doIt = function() { var a = this.obj1; var b = this.obj2; } How can i swap the values of this.obj1 and this.obj2 so obj1 becomes obj2 and obj2 be...
Porfirioporgy asked 22/4, 2013 at 16:9

2

Solved

Swap the values at two mutable locations of the same type, without deinitialising or copying either one. use std::mem; let x = &mut 5; let y = &mut 42; mem::swap(x, y); assert_eq!(42...
Axe asked 3/7, 2015 at 19:39

3

Solved

I'm trying to reverse the bytes for a 64 bit address pointer for an assignment and have this code: char swapPtr(char x){ x = (x & 0x00000000FFFFFFFF) << 32 | (x & 0xFFFFFFFF00000000)...
Bryant asked 2/2, 2014 at 6:13

7

How can I go about swapping numbers in a given list? For example: list = [5,6,7,10,11,12] I would like to swap 12 with 5. Is there an built-in Python function that can allow me to do that?
Impotence asked 29/10, 2013 at 18:51

2

Solved

i have a simple HashMap; say HashMap<char, char>. is there a way to swap two elements in this hashmap using std::mem::swap (or any other method)? Of course there is the simple way getting t...
Flounce asked 5/2, 2020 at 11:19

© 2022 - 2024 — McMap. All rights reserved.