Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- public class urok20 <T> {
- private T data=null;
- private List <urok20<T>> children=new ArrayList<>();
- private urok20<T> parent=null;
- public urok20(T data) {
- this.data=data;
- }
- public urok20<T> addChild(urok20<T> child){
- child.setParent(this);
- this.children.add(child);
- return child;
- }
- public void addChildren(List<urok20<T>> children) {
- children.forEach(each -> each.setParent(this));
- this.children.addAll(children);
- }
- public List<urok20<T>> getChildren(){
- return children;
- }
- public T getData() {
- return data;
- }
- public void Setdata(T data) {
- this.data=data;
- }
- private void setParent(urok20<T> parent) {
- this.parent=parent;
- }
- public urok20<T> getParent(){
- return parent;
- }
- private static <T> void printurok20(urok20<T> node,String appender) {
- System.out.println(appender+node.getData());
- node.getChildren().forEach(each -> printurok20(each,appender + appender));
- }
- public static void main(String[] args) {
- urok20<String> root=createurok20();
- printurok20(root," ");
- }
- private static urok20<String> createurok20() {
- urok20<String> root=new urok20<>(" Йоана и Иван");
- urok20<String> node5=root.addChild(new urok20<String>(""));
- urok20<String> node1=root.addChild(new urok20<String>(" Никол Марин Георги"));
- urok20<String> node3=root.addChild(new urok20<String>(""));
- urok20<String> node4=root.addChild(new urok20<String>(""));
- urok20<String> node11=root.addChild(new urok20<String>(" Иван и Гергана Атанас и Нина Таня и Валери"));
- urok20<String> node6=root.addChild(new urok20<String>("\n"));
- urok20<String> node111=root.addChild(new urok20<String>(" Ивайло и Даниел Мартин Йордан"));
- return root;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement