# Insert interger

• 03-01-2011, 10:49 AM
yuslaidi
Insert interger
Can anybody help me..

how to insert 8 integer let say 1,2,3,4,5,6,7,8. then swap that would be 5,6,7,8,1,2,3,4. what the suitable algorithm?

i need very urgently..

Pls help..

Thanks.
• 03-01-2011, 11:23 AM
A for loop with 0 and ++ and then a for loop with length and -- ?
• 03-10-2011, 01:55 PM
yuslaidi
My Coding is Here..
Hi all....
My stage 1 and Stage 2 is ok...but my stage 3 had problem
can anybody help me regarding this....
it must divide by 2 then for stage 3 output [4] 4, [5],2 [6]6 [7]0 not appear. What should i do.
Here i put my coding and Output also.

My Coding

import java.util.Scanner;
import java.lang.Math;
import java.util.Random;

public class block14 {

int N;
protected int m = (int) (Math.log(N) / Math.log(2));
static Random random = new Random();

protected int p= (int) (Math.pow(2,(Math.log(N)/Math.log(2)+1)/2));
int split=N/2;

public static void main(String[] args){

System.out.print("Enter Matrix Size : ");

Scanner scan = new Scanner(System.in);
int input = scan.nextInt();

System.out.println("");

int i,j,x,count;

int[] outplane = new int[input];
int[] outplane1 = new int[input];
int stage=1;
int plane=0;
int[] shuffleMatrix = new int[input];

System.out.println("(STAGE "+stage+")");
System.out.println("");

for(i=0; i<input; i++)
{
outplane1[i] = i;
}

shuffleMatrix = shuffler4(input);
for ( i = 0; i < input; i++)
{
System.out.print( "[" + outplane1[i] + "] "+ shuffleMatrix[i]);
System.out.println("");

}

if (input==2)
{
System.out.println("true");
}

else {
int a, b;
int in = input;

System.out.println("");

while(input%2 == 0 && input != 2)
{

for (j =0; j<input; j++)
{
outplane[j] = shuffleMatrix[j]/2;
}

for(j=0; j<input/2; j++)
{
for(i=j+1; i<input/2; i++)
{

if((outplane[j] == outplane[i]))
{
int split1 = outplane1[i];
int split2 = shuffleMatrix[i];
int split3 = outplane[i];

for(int m=i; m<input; m++)
{
if(m==(input-1))
{
outplane1[m] = split1;
shuffleMatrix[m] = split2;
outplane[m] = split3;
}
else
{
outplane1[m] = outplane1[m+1];
shuffleMatrix[m] = shuffleMatrix[m+1];
outplane[m] = outplane[m+1];
}
}
}
}
}
stage++;
System.out.println("(STAGE "+stage+")");
System.out.println("");

for ( i = 0; i < input/2; i++)
{
System.out.print( "[" + outplane1[i] + "] "+ shuffleMatrix[i]);
System.out.println("");

}

System.out.println("");
for ( i = input/2; i < input; i++)
{
System.out.print( "[" + outplane1[i] + "] "+ shuffleMatrix[i]);
System.out.println("");

}

System.out.println("");
input/=2;

}

stage++;
System.out.println(" ");

}

}

public static int[] shuffler4(int lens)
{
int[] nums = new int[lens];
for (int i = 0; i < lens; i++)
nums[i] = i;

// shuffle4
for (int i = 0; i < lens; i++) {
int r = (int) (Math.random() * (i+1)); // int between 0 and i
int swap = nums[r];
nums[r] = nums[i];
nums[i] = swap;
}

return nums;

}

}

http://i1197.photobucket.com/albums/...laidi12/f1.jpg
• 03-13-2011, 07:11 AM
yuslaidi
Please guys....is dat anybody can help me??
• 03-14-2011, 11:29 AM
Tolls
Can I ask why this is under the database section?
• 03-14-2011, 04:32 PM
yuslaidi
Quote:

Originally Posted by Tolls
Can I ask why this is under the database section?

So, if can't post here where should i?
• 03-14-2011, 04:53 PM
Tolls