-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinearTransposition.java
More file actions
35 lines (30 loc) · 883 Bytes
/
Copy pathLinearTransposition.java
File metadata and controls
35 lines (30 loc) · 883 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.*;
public class LinearTransposition{
public static int Tranposition(int[] num ,int key){
int n = num.length;
for(int i=0;i<n;i++){
if(num[i]==key){
int temp = num[i];
num[i]=num[i-1];
num[i-1]=temp;
return i;
}
}
return -1;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int[] num = new int[n];
for(int i=0;i<n;i++){
num[i]=sc.nextInt();
}
System.out.println("Enter the key to search");
int k =sc.nextInt();
System.out.println(Tranposition(num, k));
System.out.println("Tranaposition Array");
for(int i=0;i<n;i++){
System.out.print(num[i]+" ");
}
}
}