Advertisement
Samorokimetal

Urok 20, zadacha 1

Apr 2nd, 2020
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.23 KB | None | 0 0
  1.     import java.util.ArrayList;
  2.     import java.util.List;
  3.      
  4.     public class urok20 <T> {
  5.         private T data=null;
  6.         private List <urok20<T>> children=new ArrayList<>();
  7.         private urok20<T> parent=null;
  8.         public urok20(T data) {
  9.             this.data=data;
  10.         }
  11.         public urok20<T> addChild(urok20<T> child){
  12.             child.setParent(this);
  13.             this.children.add(child);
  14.             return child;
  15.         }
  16.         public void addChildren(List<urok20<T>> children) {
  17.             children.forEach(each -> each.setParent(this));
  18.             this.children.addAll(children);
  19.         }
  20.         public List<urok20<T>> getChildren(){
  21.             return children;
  22.         }
  23.         public T getData() {
  24.             return data;
  25.         }
  26.         public void Setdata(T data) {
  27.             this.data=data;
  28.         }
  29.         private void setParent(urok20<T> parent) {
  30.             this.parent=parent;
  31.         }
  32.         public urok20<T> getParent(){
  33.             return parent;
  34.         }
  35.      
  36.         private static <T> void printurok20(urok20<T> node,String appender) {
  37.             System.out.println(appender+node.getData());
  38.             node.getChildren().forEach(each -> printurok20(each,appender + appender));
  39.      
  40.         }
  41.         public static void main(String[] args) {
  42.             urok20<String> root=createurok20();
  43.             printurok20(root," ");
  44.      
  45.         }
  46.         private static urok20<String> createurok20() {
  47.             urok20<String> root=new urok20<>("                            Йоана и Иван");
  48.      
  49.             urok20<String> node5=root.addChild(new urok20<String>(""));
  50.      
  51.             urok20<String> node1=root.addChild(new urok20<String>("               Никол          Марин         Георги"));
  52.             urok20<String> node3=root.addChild(new urok20<String>(""));
  53.             urok20<String> node4=root.addChild(new urok20<String>(""));
  54.             urok20<String> node11=root.addChild(new urok20<String>("      Иван и Гергана      Атанас и Нина      Таня и Валери"));
  55.             urok20<String> node6=root.addChild(new urok20<String>("\n"));
  56.            
  57.      
  58.      
  59.             urok20<String> node111=root.addChild(new urok20<String>("   Ивайло и Даниел            Мартин                   Йордан"));
  60.      
  61.             return root;
  62.         }
  63.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement