swap

How to write a basic swap function in Java

I am new to java. How to write the java equivalent of the following C code. public void Swap(int &p, int &q) { int temp; temp = *p; *p = *q; *q = temp; } ...

Reorder the database record rows through front-end using php

I am using PHP/MYSQL. I want in my frontend, for the users to sort and rearrange database records entered by the user himself in an earlier stage. The records uploaded by the user may sometimes inserted into the database randomly, so in the user profile he/she might have a facility to rearrange the the rows in the database according to t...

How to swap two numbers without using temp variables or arithmetic operations?

This equation swaps two numbers without a temporary variable, but uses arithmetic operations: a = (a+b) - (b=a); How can I do it without arithmetic operations? I was thinking with XOR ...

Substitute output from variable to give another output.

I am trying to substitute output from variable to give another output. The variable i have problems with is the $apps. It gives me "syntax error: bad substitution". $appletDir is a directory with desktop shortcuts. The problem is that some shortcuts do not have the same name as the icon(png). So i need to substitute the program name wi...

C# DateTime.TryParse date year value swap. 30 Feb 02

Hi guys I have run into a datetime related problem, my program needs to varify whether a user entered date string is valid. The program is designed to process date value ranges from 01/01/2000 ~ 31/12/2020 and the string format is like "12 Feb 10". The problem I am facing is, sometimes user enters value like "30 Feb 10" (this value i...

Vector sorting: swap overload

I would like to overload swap function for std::vector of primitive types / objects. The reason is a slow sorting of vectors containing big objects using std::sort. Here is the simple but not working example. #include <vector> #include <algorithm> class Point { private: double x, y; public: Point(double xx, double yy) : x(xx), y...

Potential Problem in "Swapping values of two variables without using a third variable"

I recently came along this method for swapping the values of two variables without using a third variable. a^=b^=a^=b But when I tried the above code on different compilers, I got different results, some gave correct results, some didn't. Is anything terribly wrong with the code? ...

How do I make image slideshows with a fold effect?

Back in 2000 I had a js that let me get a very nice homepage: one picture: <pic src=x> and somehow the js changed the main picture every a predefined time period. (there was a pictures pool that was loaded at pageload) I can find such scripts now but cannot find one with fold effect (like folding a page in a book) The closet I got w...

Swapping two string pointers

i have to char[] in C and i wanted to swap between them, by only swaping the pointer to the array and not one char at a time so i wrote this code: #include <stdio.h> void fastSwap (char **i, char **d) { char *t = *d; *d = *i; *i = t; } int main () { char num1[] = "012345678910"; char num2[] = "abcdefghujk"; fastS...

Swap the contents of 2 JavaScript variables from one to the other.

Basically what I am wanting to do is take the variable named FROM and swap it with the variable named TO and vice visa, the reason for this is to allow the user to press a button which swaps the variables over when pressed. Exactly how it does when you press the swap button on google translate. Below is the code for the variables ect, b...

Swapping elements in an NSMutableArray

Are there any special methods to make swapping elements in an NSMutableArray easier or more direct? ...

Swap two variables without using ref/out in C#

Is it possible to swap two variables without using ref/out keyword in C#(i.e. by using unsafe)? for ex, swap(ref x,ref y);//It is possbile to by passing the reference But, Is there any other way of doing the same thing. In the swap function you can use a temp variable. But, How to swap the variables without using ref/out keyw...

Three20, different images for portrait and landscape orientation possible?

I am using three20 to present a photo essay of a story I made after the February earthquake in Chile. I would like the app to display portrait type images when iPad device is in portrait orientation and landscape type images when iPad device is in landscape orientation. So there would be two versions of every image, one cropped for portr...

Why swap with xor works fine in c++ but in java doesn't ? some puzzle

Possible Duplicate: Why is this statement not working in java x ^= y ^= x ^= y; Sample code int a=3; int b=4; a^=(b^=(a^=b)); In c++ it swaps variables, but in java we get a=0, b=4 why? ...

bit swapping with char type in C

the data type is char, and the pattern is follow: source byte: [0][1][2][3][4][5][6][7] destination: [6][7][4][5][2][3][0][1] for example, if I pass a char, 29 to this function, it will do the swapping and return a char type value, which is 116. How can I do the swapping? thank you. ======================== Just wondering if I can...

Swapping elements in a Common Lisp list.

Is there a Common Lisp function that will swap two elements in a list given their indices and return the modified list? ...

FORTRAN 77 - SWAP

With FORTRAN 77 is it possible to perform a swap on two arrays, in the same way swap works in c++? I have two large arrays, e.g. v1 and v2, and would like to swap v1 and v2 at the end of each iteration such that v2 is always the last iteration and v1 is the working array. How does one do this in F77? ...

Reorder function arguments in Lisp

I'm interested in an operator, "swap-arg", that takes as input 1) a function f of n variables, and 2) index k, and then returns a the same function except with the first and kth input variables swapped. eg (in mathematical notation): (swap-arg(f,2))(x,y,z,w) = f(z,y,x,w) Now my first idea is to implement this using rotatef as follows, ...