-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathInversePermutation.java
More file actions
43 lines (35 loc) · 824 Bytes
/
InversePermutation.java
File metadata and controls
43 lines (35 loc) · 824 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
36
37
38
39
40
41
42
43
// Naive java Program to find inverse permutation.
import java.io.*;
class InversePer {
// java function to find inverse permutations
static void inversePermutation(int arr[], int size)
{
int i ,j;
// Loop to select Elements one by one
for ( i = 0; i < size; i++)
{
// Loop to print position of element
// where we find an element
for ( j = 0; j < size; j++)
{
// checking the element in
// increasing order
if (arr[j] == i + 1)
{
// print position of element
// where element is in inverse
// permutation
System.out.print( j + 1 + " ");
break;
}
}
}
}
// Driver program to test above function
public static void main (String[] args)
{
int arr[] = {2, 3, 4, 5, 1};
int size = arr.length;
inversePermutation(arr, size);
}
}