-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveElement.java
More file actions
30 lines (28 loc) · 501 Bytes
/
Copy pathRemoveElement.java
File metadata and controls
30 lines (28 loc) · 501 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
package Array;
public class RemoveElement
{
public int removeElement(int[] A, int elem)
{
int end = A.length-1;
for (int i = 0; i < end+1; i++)
{
if (A[i] == elem)
{
int temp = A[i];
A[i--] = A[end];
A[end--] = temp;
}
}
return end+1;
}
public static void main(String[] args)
{
RemoveElement removeElement = new RemoveElement();
int A[] = {1};
System.out.println(removeElement.removeElement(A, 1));
for (int i : A)
{
System.out.println(i);
}
}
}