-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq10p2.java
More file actions
44 lines (41 loc) · 1.15 KB
/
Copy pathq10p2.java
File metadata and controls
44 lines (41 loc) · 1.15 KB
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
44
import java.util.*;
public class q10p2{
public static void main(String[] args){
String[] test = {"abcdcba", "asbe", "12344321", "qqqqa", "qwertyu","zazaaa","oiuyuio"};
sort(test);
for(String str : test){
System.out.print(str+" ");
}
System.out.println(" ");
}
public static void sort(String[] arr){
int left = 0;
int right = arr.length - 1;
while(left <= right){
while(check(arr[left]))
left++;
while(!check(arr[right]))
right--;
if(left <= right && left < arr.length && right > 0)
swap(left, right, arr);
}
}
public static void swap(int a, int b, String[] str){
String buf = "";
buf = str[a];
str[a] = str[b];
str[b] = buf;
}
public static boolean check(String str){
int left = 0;
int right = str.length()-1;
while(left <= right){
if(str.charAt(left) == str.charAt(right)){
left++;
right--;
}else
return false;
}
return true;
}
}