package sortSubdivision;

import java.util.*;

public class Sort {
    public static void main(String[] args) {

        System.out.println("Туда");

        List<String> list = new ArrayList<>();
        list.add("K1\\SK1");
        list.add("K1\\SK2");
        list.add("K1\\SK1\\SSK1");
        list.add("K1\\SK1\\SSK2");
        list.add("K2");
        list.add("K2\\SK1\\SSK1");
        list.add("K2\\SK1\\SSK2");
        Collections.sort(list);

        // по порядку
        list.forEach(System.out::println);

        System.out.println("Обратно");
        // в обратном порядке

        final Iterator<String> iterator = new LinkedList<>(list).descendingIterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }
}

@@ -40,16 +40,56 @@
 til.*;%0A%0A
+import static java.lang.String.format;%0A%0A
 public c
@@ -150,45 +150,8 @@
  %7B%0A%0A
-        System.out.println(%22%D0%A2%D1%83%D0%B4%D0%B0%22);%0A%0A
     
@@ -217,17 +217,17 @@
 (%22K1%5C%5CSK
-1
+2
 %22);%0A    
@@ -232,36 +232,42 @@
       list.add(%22
+K2%5C%5CS
 K1%5C%5C
+S
 SK2%22);%0A        l
@@ -278,30 +278,24 @@
 add(%22K1%5C%5CSK1
-%5C%5CSSK1
 %22);%0A        
@@ -356,33 +356,33 @@
      list.add(%22K
-2
+1
 %5C%5CSK1%5C%5CSSK1%22);%0A 
@@ -410,29 +410,30 @@
 SK1%5C%5CSSK
-2
+1
 %22);%0A
+%0A
         
 Collecti
@@ -428,167 +428,391 @@
     
-Collections.sort(list);%0A%0A        // %D0%BF%D0%BE %D0%BF%D0%BE%D1%80%D1%8F%D0%B4%D0%BA%D1%83%0A        list.forEach(System.out::println);%0A%0A        System.out.println(%22%D0%9E%D0%B1%D1%80%D0%B0%D1%82%D0%BD%D0%BE%22);%0A        // %D0%B2 %D0%BE%D0%B1%D1%80%D0%B0%D1%82%D0%BD%D0%BE%D0%BC %D0%BF%D0%BE%D1%80%D1%8F%D0%B4%D0%BA%D0%B5
+final List%3CString%3E result = new Sort().restorationStructure(list);%0A%0A        System.out.println(%22=============%22);%0A        System.out.println(%22=== %D0%A2%D1%83%D0%B4%D0%B0%D1%81 ===%22);%0A        System.out.println(%22=============%22);%0A        result.forEach(System.out::println);%0A%0A        System.out.println(%22=============%22);%0A        System.out.println(%22== %D0%9E%D0%B1%D1%80%D0%B0%D1%82%D0%BD%D0%BE ==%22);%0A        System.out.println(%22=============%22);
 %0A%0A  
@@ -840,17 +840,20 @@
 String%3E 
-i
+desI
 terator 
@@ -871,19 +871,21 @@
 dList%3C%3E(
-lis
+resul
 t).desce
@@ -897,24 +897,25 @@
 Iterator();%0A
+%0A
         whil
@@ -917,17 +917,20 @@
  while (
-i
+desI
 terator.
@@ -977,22 +977,630 @@
 tln(
-iterator.next(
+desIterator.next());%0A        %7D%0A    %7D%0A%0A    public List%3CString%3E restorationStructure(final List%3CString%3E src) %7B%0A        final Set%3CString%3E set = new HashSet%3C%3E();%0A        for (String fullPath : src) %7B%0A            String%5B%5D split = fullPath.split(%22%5C%5C%5C%5C%22);%0A            set.add(fullPath);%0A%0A            String append = %22%22;%0A            for (int i = 0; i %3C split.length - 1; i++) %7B%0A                set.add(append = format(%22%25s%25s%5C%5C%22, append, split%5Bi%5D));%0A            %7D%0A        %7D%0A%0A        src.clear();%0A        for (String s : set) %7B%0A            if (s.charAt(s.length() - 1) == '%5C%5C') %7B%0A                src.add(s.substring(0, s.length() - 1
 ));%0A
@@ -1603,22 +1603,229 @@
 ));%0A        
+ 
-%7D
+   %7D else %7B%0A                src.add(s);%0A            %7D%0A        %7D%0A%0A        set.clear();%0A        set.addAll(src);%0A        src.clear();%0A        src.addAll(set);%0A        Collections.sort(src);%0A        return src;
 %0A    %7D%0A%7D%0A

add sort