Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.example;
- import java.util.ArrayList;
- import java.util.List;
- public class Main {
- public static void main(String[] args) {
- List<Character> abobus = new ArrayList<>();
- abobus.add('A');
- abobus.add('A');
- abobus.add('A');
- abobus.add('C');
- abobus.add('B');
- abobus.add('B');
- abobus.add('A');
- abobus.add('A');
- abobus.add('A');
- abobus.add('B');
- abobus.add('B');
- abobus.add('C');
- abobus.add('B');
- abobus.add('B');
- aboba(0, abobus.size() - 1, abobus);
- System.out.println(abobus);
- }
- public static void swap(List<Character> a, int i, int j) {
- Character tmp = a.get(i);
- a.set(i, a.get(j));
- a.set(j, tmp);
- }
- public static void aboba(int low, int high, List<Character> a) {
- if(low >= high){
- return;
- }
- int lt, gt, i;
- lt = low;
- gt = high;
- i = lt;
- while (i != gt) {
- if (a.get(i).equals(a.get(lt))) {
- i++;
- } else {
- if (a.get(i) < a.get(lt)) {
- swap(a, lt++, i++);
- } else {
- swap(a, gt--, i);
- }
- }
- }
- aboba(low, lt - 1, a);
- aboba(gt + 1, high, a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement