gitweb on Svarog

projekti pod git sistemom za održavanje verzija -- projects under the git version control system
Primer implementacije binarnih stabala sa opstim tipom podataka
authorIvan Pribela <ivanpribela@gmail.com>
Sat, 19 Dec 2015 15:42:17 +0000 (16:42 +0100)
committerDoni Pracner <quinnuendo@gmail.com>
Sat, 19 Dec 2015 15:42:17 +0000 (16:42 +0100)
Data je implementacija i zadatak za vezbu. Takodje je dato i resenje
zadatka u odvojenom fajlu.

Stabla/StabloOpstegTipa/Konverter.java [new file with mode: 0644]
Stabla/StabloOpstegTipa/Osoba.java [new file with mode: 0644]
Stabla/StabloOpstegTipa/Osobe.txt [new file with mode: 0644]
Stabla/StabloOpstegTipa/ResenoStabloProgram.java [new file with mode: 0644]
Stabla/StabloOpstegTipa/StabloIOPretty.java [new file with mode: 0644]
Stabla/StabloOpstegTipa/StabloProgram.java [new file with mode: 0644]
Stabla/StabloOpstegTipa/_zadatak-stabla.txt [new file with mode: 0644]

diff --git a/Stabla/StabloOpstegTipa/Konverter.java b/Stabla/StabloOpstegTipa/Konverter.java
new file mode 100644 (file)
index 0000000..421c1ce
--- /dev/null
@@ -0,0 +1,33 @@
+// Instance ove klase konvertuju string u neki konkretan tip podataka i obratno\r
+// Takodje je dato par gotovih implementacija konvertera\r
+public interface Konverter<T> {\r
+\r
+       public String toString(T element);\r
+       public T fromString(String string);\r
+\r
+       public static Konverter<Integer> INTEGER = new Konverter<Integer>() {\r
+               @Override public String toString(Integer element) { return element == null ? null : element.toString(); }\r
+               @Override public Integer fromString(String string) { return string == null ? null : Integer.parseInt(string); }\r
+       };\r
+\r
+       public static Konverter<Long> LONG = new Konverter<Long>() {\r
+               @Override public String toString(Long element) { return element == null ? null : element.toString(); }\r
+               @Override public Long fromString(String string) { return string == null ? null : Long.parseLong(string); }\r
+       };\r
+\r
+       public static Konverter<Double> DOUBLE = new Konverter<Double>() {\r
+               @Override public String toString(Double element) { return element == null ? null : element.toString(); }\r
+               @Override public Double fromString(String string) { return string == null ? null : Double.parseDouble(string); }\r
+       };\r
+\r
+       public static Konverter<String> STRING = new Konverter<String>() {\r
+               @Override public String toString(String element) { return element; }\r
+               @Override public String fromString(String string) { return string; }\r
+       };\r
+\r
+       public static Konverter<Osoba> OSOBA = new Konverter<Osoba>() {\r
+               @Override public String toString(Osoba element) { return element == null ? null : element.getIme() + " " + element.getPrezime() + " " + element.getGodinaRodjenja(); }\r
+               @Override public Osoba fromString(String string) { if (string == null) return null; else { String[] delovi = string.split(" "); return new Osoba(delovi[0], delovi[1], Integer.parseInt(delovi[2]));} }\r
+       };\r
+       \r
+}\r
diff --git a/Stabla/StabloOpstegTipa/Osoba.java b/Stabla/StabloOpstegTipa/Osoba.java
new file mode 100644 (file)
index 0000000..6971b1c
--- /dev/null
@@ -0,0 +1,72 @@
+import java.util.Objects;\r
+\r
+// Tip podataka koji predstavlja jednu osobu\r
+public class Osoba {\r
+\r
+       private final String ime;\r
+       private final String prezime;\r
+       private final int godinaRodjenja;\r
+\r
+       public Osoba(String ime, String prezime, int godinaRodjenja) {\r
+               if (ime == null) {\r
+                       throw new IllegalArgumentException("ime");\r
+               }\r
+               this.ime = ime;\r
+               if (prezime == null) {\r
+                       throw new IllegalArgumentException("prezime");\r
+               }\r
+               this.prezime = prezime;\r
+               this.godinaRodjenja = godinaRodjenja;\r
+       }\r
+\r
+       public String getIme() {\r
+               return ime;\r
+       }\r
+\r
+       public String getPrezime() {\r
+               return prezime;\r
+       }\r
+\r
+       public int getGodinaRodjenja() {\r
+               return godinaRodjenja;\r
+       }\r
+\r
+       @Override\r
+       public int hashCode() {\r
+               final int prostBroj = 31;\r
+               int rezultat = 1;\r
+               rezultat = prostBroj * rezultat + godinaRodjenja;\r
+               rezultat = prostBroj * rezultat + ime.hashCode();\r
+               rezultat = prostBroj * rezultat + prezime.hashCode();\r
+               return rezultat;\r
+       }\r
+\r
+       @Override\r
+       public boolean equals(Object obj) {\r
+               if (this == obj) {\r
+                       return true;\r
+               }\r
+               if (obj == null) {\r
+                       return false;\r
+               }\r
+               if (getClass() != obj.getClass()) {\r
+                       return false;\r
+               }\r
+               Osoba that = (Osoba) obj;\r
+               if (this.godinaRodjenja != that.godinaRodjenja) {\r
+                       return false;\r
+               }\r
+               if (!Objects.equals(this.ime, that.ime)) {\r
+                       return false;\r
+               }\r
+               if (!Objects.equals(this.prezime, that.prezime)) {\r
+                       return false;\r
+               }\r
+               return true;\r
+       }\r
+\r
+       @Override\r
+       public String toString() {\r
+               return ime + " " + prezime + " " + godinaRodjenja;\r
+       }\r
+}\r
diff --git a/Stabla/StabloOpstegTipa/Osobe.txt b/Stabla/StabloOpstegTipa/Osobe.txt
new file mode 100644 (file)
index 0000000..04cf8d0
--- /dev/null
@@ -0,0 +1,99 @@
+                /-----(o) Pera Peric 1953\r
+                |\r
+         /-----(o) Paja Pajic 1962\r
+         |      |\r
+         |      |             /-----(o) Mitar Mitrovic 1958\r
+         |      |             |      |\r
+         |      |             |      \-----(o) Dara Darinkov 1968\r
+         |      |             |\r
+         |      |      /-----(o) Mile Milic 1962\r
+         |      |      |      |\r
+         |      |      |      |      /-----(o) Stefan Stefan-Stefan 1948\r
+         |      |      |      |      |\r
+         |      |      |      \-----(o) Nemanja Nemanjic 1979\r
+         |      |      |\r
+         |      \-----(o) Svetozar Svetozarevic 1954\r
+         |             |\r
+         |             \-----(o) Zlaja Zlajic 1981\r
+         |\r
+  /-----(o) Vuk Wolfeschlegelsteinhausenberger 1966\r
+  |      |\r
+  |      |      /-----(o) Nina Ninkov 1971\r
+  |      |      |\r
+  |      \-----(o) Raja Rajkovic 1985\r
+  |             |\r
+  |             |      /-----(o) Djoka Djokic 1979\r
+  |             |      |\r
+  |             \-----(o) Srbislava Srbislavac 1969\r
+  |                    |\r
+  |                    \-----(o) Nikolina Nikolic 1944\r
+  |                           |\r
+  |                           \-----(o) Zvonko Zvonkov 1983\r
+  |\r
+-(o) Petar Petrovic 1945\r
+  |\r
+  |      /-----(o) Marko Markovic 1923\r
+  |      |      |\r
+  |      |      |      /-----(o) Jakov Karajakov 1966\r
+  |      |      |      |      |\r
+  |      |      |      |      |      /-----(o) Janko Jankovic 1959\r
+  |      |      |      |      |      |\r
+  |      |      |      |      \-----(o) Tuta Tutevski 1974\r
+  |      |      |      |             |\r
+  |      |      |      |             \-----(o) Zorana Zoranovic-Zoranovski 1955\r
+  |      |      |      |\r
+  |      |      \-----(o) Zdravko Dren 1823\r
+  |      |             |\r
+  |      |             \-----(o) Filip Filipovic 1957\r
+  |      |\r
+  \-----(o) Maja Majic 1972\r
+         |\r
+         |                    /-----(o) Mislav Mislavski 1960\r
+         |                    |\r
+         |             /-----(o) Ljubisava Ljubisavljevic 1959\r
+         |             |      |\r
+         |             |      |             /-----(o) Pera Peric 1973\r
+         |             |      |             |\r
+         |             |      |      /-----(o) Joksim Joksimovic 1959\r
+         |             |      |      |      |\r
+         |             |      |      |      \-----(o) Mika Mikic 1970\r
+         |             |      |      |             |\r
+         |             |      |      |             \-----(o) Baja Bajic 1967\r
+         |             |      |      |\r
+         |             |      \-----(o) Zrinko Zrinkovic 1965\r
+         |             |             |\r
+         |             |             \-----(o) Hadzija Hadzi-Hadzic 1963\r
+         |             |                    |\r
+         |             |                    \-----(o) Jova Jovic 1943\r
+         |             |                           |\r
+         |             |                           \-----(o) Tatjana Tatjanic 1972\r
+         |             |                                  |\r
+         |             |                                  \-----(o) Leposava Leposavljevic 1981\r
+         |             |                                         |\r
+         |             |                                         |      /-----(o) Zora Zoric 1969\r
+         |             |                                         |      |\r
+         |             |                                         \-----(o) Milos Milosevic 1953\r
+         |             |                                                |\r
+         |             |                                                \-----(o) Jovan Jovanovic 1975\r
+         |             |\r
+         |      /-----(o) Ivana Ivanovic 1977\r
+         |      |\r
+         \-----(o) Marinko Marinkovic 1965\r
+                |\r
+                \-----(o) Marina Marinovic 1984\r
+                       |\r
+                       \-----(o) Gojko Gojkovic 1967\r
+                              |\r
+                              |             /-----(o) Milan McMilan 1966\r
+                              |             |      |\r
+                              |             |      |             /-----(o) Milena Mileski 1977\r
+                              |             |      |             |\r
+                              |             |      |      /-----(o) Miladinka Miladinovic 1964\r
+                              |             |      |      |\r
+                              |             |      \-----(o) Nikola Nikolic-Nikolic 1981\r
+                              |             |             |\r
+                              |             |             \-----(o) Danijela Danijelac 1979\r
+                              |             |\r
+                              |      /-----(o) Strahinja Strahimirovic 1976\r
+                              |      |\r
+                              \-----(o) Lazar Lazarevic 1976\r
diff --git a/Stabla/StabloOpstegTipa/ResenoStabloProgram.java b/Stabla/StabloOpstegTipa/ResenoStabloProgram.java
new file mode 100644 (file)
index 0000000..e0f310d
--- /dev/null
@@ -0,0 +1,502 @@
+import java.util.Comparator;\r
+import java.util.NoSuchElementException;\r
+import java.util.Objects;\r
+\r
+// Tip podataka koji sadrzi binarno stablo\r
+class BinarnoStablo<T> {\r
+\r
+       // Tip podataka koji opisuje jedan cvor stabla\r
+       private static class Cvor<T> {\r
+               \r
+               T element;\r
+               Cvor<T> levo;\r
+               Cvor<T> desno;\r
+\r
+               Cvor(T element, Cvor<T> levo, Cvor<T> desno) {\r
+                       this.element = element;\r
+                       this.levo = levo;\r
+                       this.desno = desno;\r
+               }\r
+       }\r
+\r
+       // Cvor koji je koren stabla\r
+       // Ako je stablo prazno, koren je null\r
+       protected Cvor<T> koren;\r
+\r
+       // Kreiramo prazno stablo\r
+       public BinarnoStablo() {\r
+               koren = null;\r
+       }\r
+\r
+       // Kreiramo stablo sa datim elementom u korenu\r
+       // bez levog i desnog podstabla\r
+       public BinarnoStablo(T element) {\r
+               koren = new Cvor<>(element, null, null);\r
+       }\r
+\r
+       // Kreiramo novo stablo sa datim elementom u korenu\r
+       // i datim levim i desnim podstablom\r
+       public BinarnoStablo(T element, BinarnoStablo<T> levo, BinarnoStablo<T> desno) {\r
+               koren = new Cvor<T>(element, levo.koren, desno.koren);\r
+       }\r
+\r
+       // Zasticeni konstruktor za kreiranje novog stabla\r
+       // sa korenom u datom cvoru ovog stabla\r
+       protected BinarnoStablo(Cvor<T> koren) {\r
+               this.koren = koren;\r
+       }\r
+\r
+       public T getElement() {\r
+               if (koren == null) { // Stablo je prazno\r
+                       throw new NoSuchElementException();\r
+               }\r
+               return koren.element;\r
+       }\r
+\r
+       public void setElement(T element) {\r
+               if (koren == null) { // Stablo je prazno\r
+                       throw new NoSuchElementException();\r
+               }\r
+               koren.element = element;\r
+       }\r
+\r
+       public BinarnoStablo<T> getLevoPodstablo() {\r
+               if (koren == null) { // Stablo je prazno\r
+                       throw new NoSuchElementException();\r
+               }\r
+               if (koren.levo == null) { // Nema levog podstabla\r
+                       return null;\r
+               }\r
+               return new BinarnoStablo<T>(koren.levo);\r
+       }\r
+\r
+       public void setLevoPodstablo(BinarnoStablo<T> levo) {\r
+               if (koren == null) { // Stablo je prazno\r
+                       throw new NoSuchElementException();\r
+               }\r
+               if (levo == null) {\r
+                       koren.levo = null;\r
+               } else {\r
+                       koren.levo = levo.koren;\r
+               }\r
+       }\r
+\r
+       public BinarnoStablo<T> getDesnoPodstablo() {\r
+               if (koren == null) { // Stablo je prazno\r
+                       throw new NoSuchElementException();\r
+               }\r
+               if (koren.desno == null) {\r
+                       return null;\r
+               }\r
+               return new BinarnoStablo<T>(koren.desno);\r
+       }\r
+\r
+       public void setDesnoPodstablo(BinarnoStablo<T> desno) {\r
+               if (koren == null) { // Stablo je prazno\r
+                       throw new NoSuchElementException();\r
+               }\r
+               if (desno == null) {\r
+                       koren.desno = null;\r
+               } else {\r
+                       koren.desno = desno.koren;\r
+               }\r
+       }\r
+\r
+       //DatoNaVezbama\r
+       public int brojElemenata() {\r
+               // Spremimo argumente i pozovemo rekurzivni metod\r
+               return brojElemenata(koren);\r
+       }\r
+\r
+       // Metod koji zapravo resava dati problem\r
+       //DatoNaVezbama\r
+       protected static <T> int brojElemenata(Cvor<T> cvor) {\r
+               if (cvor == null) {\r
+                       return 0;\r
+               }\r
+               int broj = 1;\r
+               broj = broj + brojElemenata(cvor.levo);\r
+               broj = broj + brojElemenata(cvor.desno);\r
+               return broj;\r
+       }\r
+\r
+       //DatoNaVezbama\r
+       public int brojNivoa() {\r
+               // Spremimo argumente i pozovemo rekurzivni metod\r
+               return brojNivoa(koren);\r
+       }\r
+\r
+       // Metod koji zapravo resava dati problem\r
+       //DatoNaVezbama\r
+       protected static <T> int brojNivoa(Cvor<T> cvor) {\r
+               if (cvor == null) {\r
+                       return 0;\r
+               }\r
+               int brojNivoaLevog = brojNivoa(cvor.levo);\r
+               int brojNivoaDesnog = brojNivoa(cvor.desno);\r
+               return Math.max(brojNivoaLevog, brojNivoaDesnog) + 1;\r
+       }\r
+\r
+       public boolean jePrazno() {\r
+               return koren == null;\r
+       }\r
+\r
+       public boolean postojiElement(T element) {\r
+               return postojiElement(koren, element);\r
+       }\r
+       \r
+       protected static <T> boolean postojiElement(Cvor<T> cvor, T element) {\r
+               if (cvor == null) {\r
+                       return false;\r
+               }\r
+               if (Objects.equals(cvor.element, element)) {\r
+                       return true;\r
+               }\r
+               if (postojiElement(cvor.levo, element)) {\r
+                       return true;\r
+               }\r
+               if (postojiElement(cvor.desno, element)) {\r
+                       return true;\r
+               }\r
+               return false;\r
+       }\r
+\r
+       public T min(Comparator<T> komparator) {\r
+               return min(koren, komparator);\r
+       }\r
+\r
+       protected static <T> T min(Cvor<T> cvor, Comparator<T> komparator) {\r
+               if (cvor == null) {\r
+                       return null;\r
+               }\r
+               T min = cvor.element;\r
+               T levoMin = min(cvor.levo, komparator);\r
+               if (komparator.compare(min, levoMin) > 0) {\r
+                       min = levoMin;\r
+               }\r
+               T desnoMin = min(cvor.desno, komparator);\r
+               if (komparator.compare(min, desnoMin) > 0) {\r
+                       min = desnoMin;\r
+               }\r
+               return min;\r
+       }\r
+       \r
+       public T max(Comparator<T> komparator) {\r
+               return max(koren, komparator);\r
+       }\r
+\r
+       protected static <T> T max(Cvor<T> cvor, Comparator<T> komparator) {\r
+               if (cvor == null) {\r
+                       return null;\r
+               }\r
+               T max = cvor.element;\r
+               T levoMax = max(cvor.levo, komparator);\r
+               if (komparator.compare(max, levoMax) > 0) {\r
+                       max = levoMax;\r
+               }\r
+               T desnoMax = max(cvor.desno, komparator);\r
+               if (komparator.compare(max, desnoMax) > 0) {\r
+                       max = desnoMax;\r
+               }\r
+               return max;\r
+       }\r
+\r
+       public BinarnoStablo<T> pronadji(T element) {\r
+               Cvor<T> cvor = pronadji(koren, element);\r
+               if (cvor == null) {\r
+                       return null;\r
+               }\r
+               return new BinarnoStablo<>(cvor);\r
+       }\r
+\r
+       protected static <T> Cvor<T> pronadji(Cvor<T> cvor, T element) {\r
+               if (cvor == null) {\r
+                       return null;\r
+               }\r
+               if (Objects.equals(cvor.element, element)) {\r
+                       return cvor;\r
+               }\r
+               Cvor<T> nadjenLevo = pronadji(cvor.levo, element);\r
+               if (nadjenLevo != null) {\r
+                       return nadjenLevo;\r
+               }\r
+               Cvor<T> nadjenDesno = pronadji(cvor.desno, element);\r
+               if (nadjenDesno != null) {\r
+                       return nadjenDesno;\r
+               }\r
+               return null;\r
+       }\r
+\r
+       public boolean ubaci(T roditelj, T potomak, boolean levo) {\r
+               return ubaci(koren, roditelj, potomak, levo);\r
+       }\r
+\r
+       protected static <T> boolean ubaci(Cvor<T> cvor, T roditelj, T potomak, boolean levo) {\r
+               cvor = pronadji(cvor, roditelj);\r
+               if (cvor == null) {\r
+                       return false;\r
+               }\r
+               if (levo) {\r
+                       if (cvor.levo != null) {\r
+                               return false;\r
+                       }\r
+                       cvor.levo = new Cvor<T>(potomak, null, null);\r
+               } else {\r
+                       if (cvor.desno != null) {\r
+                               return false;\r
+                       }\r
+                       cvor.desno = new Cvor<T>(potomak, null, null);\r
+               }\r
+               return true;\r
+       }\r
+\r
+       public BinarnoStablo<T> roditeljOd(T potomak) {\r
+               Cvor<T> cvor = roditeljOd(koren, null, potomak);\r
+               if (cvor == null) {\r
+                       return null;\r
+               }\r
+               return new BinarnoStablo<>(cvor);\r
+       }\r
+       \r
+       protected static <T> Cvor<T> roditeljOd(Cvor<T> cvor, Cvor<T> roditelj, T potomak) {\r
+               if (cvor == null) {\r
+                       return null;\r
+               }\r
+               if (Objects.equals(cvor.element, potomak)) {\r
+                       return roditelj;\r
+               }\r
+               Cvor<T> roditeljLevo = roditeljOd(cvor.levo, cvor, potomak);\r
+               if (roditeljLevo != null) {\r
+                       return roditeljLevo;\r
+               }\r
+               Cvor<T> roditeljDesno = roditeljOd(cvor.desno, cvor, potomak);\r
+               if (roditeljDesno != null) {\r
+                       return roditeljDesno;\r
+               }\r
+               return null;\r
+       }\r
+\r
+       public BinarnoStablo<T> kopija() {\r
+               return new BinarnoStablo<T>(kopija(koren));\r
+       }\r
+\r
+       protected static <T> Cvor<T> kopija(Cvor<T> cvor) {\r
+               if (cvor == null) {\r
+                       return null;\r
+               }\r
+               return new Cvor<T>(cvor.element, kopija(cvor.levo), kopija(cvor.desno));\r
+       }\r
+\r
+       public BinarnoStablo<T> obrnuto() {\r
+               return new BinarnoStablo<T>(obrnuto(koren));\r
+       }\r
+\r
+       protected static <T> Cvor<T> obrnuto(Cvor<T> cvor) {\r
+               if (cvor == null) {\r
+                       return null;\r
+               }\r
+               return new Cvor<T>(cvor.element, obrnuto(cvor.desno), obrnuto(cvor.levo));\r
+       }\r
+\r
+       public void stampajPreorder() {\r
+               stampajPreorder(koren);\r
+       }\r
+       protected static <T> void stampajPreorder(Cvor<T> cvor) {\r
+               if (cvor == null) {\r
+                       return;\r
+               }\r
+               Svetovid.out.println(cvor.element);\r
+               stampajPreorder(cvor.levo);\r
+               stampajPreorder(cvor.desno);\r
+       }\r
+\r
+       public void stampajInorder() {\r
+               stampajInorder(koren);\r
+       }\r
+       \r
+       protected static <T> void stampajInorder(Cvor<T> cvor) {\r
+               if (cvor == null) {\r
+                       return;\r
+               }\r
+               stampajInorder(cvor.levo);\r
+               Svetovid.out.println(cvor.element);\r
+               stampajInorder(cvor.desno);\r
+       }\r
+       \r
+       public void stampajPostorder() {\r
+               stampajPostorder(koren);\r
+       }\r
+       \r
+       protected static <T> void stampajPostorder(Cvor<T> cvor) {\r
+               if (cvor == null) {\r
+                       return;\r
+               }\r
+               stampajPostorder(cvor.levo);\r
+               stampajPostorder(cvor.desno);\r
+               Svetovid.out.println(cvor.element);\r
+       }\r
+       \r
+       public void stampajListove() {\r
+               stampajListove(koren);\r
+       }\r
+       \r
+       protected static <T> void stampajListove(Cvor<T> cvor) {\r
+               if (cvor == null) {\r
+                       return;\r
+               }\r
+               if ((cvor.levo == null) && (cvor.desno == null)) {\r
+                       Svetovid.out.println(cvor.element);\r
+               }\r
+               stampajListove(cvor.levo);\r
+               stampajListove(cvor.desno);\r
+       }\r
+       \r
+       public void stampajSveIspod(T element) {\r
+               stampajSveIspod(koren, element);\r
+       }\r
+       \r
+       protected static <T> void stampajSveIspod(Cvor<T> cvor, T element) {\r
+               Cvor<T> nadjen = pronadji(cvor, element);\r
+               if (nadjen != null) {\r
+                       stampajInorder(nadjen.levo);\r
+                       stampajInorder(nadjen.desno);\r
+               }\r
+       }\r
+}\r
+\r
+       //definisemo neke komparatore za konkretnu klasu koju cemo\r
+       // ubacivati u nase stablo\r
+\r
+       class KomparatorPoStarosti implements Comparator<Osoba> {\r
+               public int compare(Osoba o1, Osoba o2) {\r
+                       if (o1 == null && o2 == null) {\r
+                               return 0;\r
+                       }\r
+                       if (o1 == null) {\r
+                               return 1;\r
+                       }\r
+                       if (o2 == null) {\r
+                               return -1;\r
+                       }\r
+                       return o2.getGodinaRodjenja() - o1.getGodinaRodjenja();\r
+               }\r
+       }\r
+       \r
+       class KomparatorPoDuziniPrezimena implements Comparator<Osoba> {\r
+               public int compare(Osoba o1, Osoba o2) {\r
+                       if (o1 == null && o2 == null) {\r
+                               return 0;\r
+                       }\r
+                       if (o1 == null) {\r
+                               return 1;\r
+                       }\r
+                       if (o2 == null) {\r
+                               return -1;\r
+                       }\r
+                       return o2.getPrezime().length() - o1.getPrezime().length();\r
+               }\r
+       }\r
+\r
+// Glavna klasa\r
+public class ResenoStabloProgram {\r
+\r
+       // Glavni program\r
+       public static void main(String[] args) {\r
+\r
+               // Kreiramo objekat koji koristimo za ucitavanje i ispisivanje stabla\r
+               StabloIOPretty<Osoba> io = new StabloIOPretty<>(Konverter.OSOBA);\r
+\r
+               // Ucitamo stablo\r
+               BinarnoStablo<Osoba> stablo = io.readStablo(Svetovid.in("Osobe.txt"));\r
+\r
+               // Ispisemo ucitano stablo na ekran\r
+               Svetovid.out.println("Ucitano stablo:");\r
+               io.printStablo(Svetovid.out, stablo);\r
+               Svetovid.out.println();\r
+\r
+               // Ilustrujemo pozive metoda\r
+               \r
+               int brojElemenata = stablo.brojElemenata();\r
+               Svetovid.out.println();\r
+               Svetovid.out.println("Broj elemenata je ", brojElemenata);\r
+               \r
+               int brojNivoa = stablo.brojNivoa();\r
+               Svetovid.out.println("Broj nivoa je ", brojNivoa);\r
+\r
+               if (stablo.jePrazno()) {\r
+                       Svetovid.out.println("Stablo je prazno");\r
+               } else {\r
+                       Svetovid.out.println("Stablo nije prazno");\r
+               }\r
+               \r
+               Osoba o1 = new Osoba("Lazar", "Lazarevic", 1976);\r
+               if (stablo.postojiElement(o1)) {\r
+                       Svetovid.out.println(o1 + " se nalazi u stablu");\r
+               } else {\r
+                       Svetovid.out.println(o1 + " se ne nalazi u stablu");\r
+               }\r
+\r
+               Osoba najmladji = stablo.min(new KomparatorPoStarosti());\r
+               Svetovid.out.println("Najmladja osoba je " + najmladji);\r
+\r
+               Osoba najduzePrezime = stablo.max(new KomparatorPoDuziniPrezimena());\r
+               Svetovid.out.println("Osoba sa najduzim prezimenom je " + najduzePrezime);\r
+\r
+               BinarnoStablo<Osoba> podstablo = stablo.pronadji(o1);\r
+               if (podstablo != null) {\r
+                       Svetovid.out.println("Podstablo sa korenom u " + o1 + ":");\r
+                       io.printStablo(Svetovid.out, podstablo);\r
+               } else {\r
+                       Svetovid.out.println("Podstablo sa korenom u " + o1 + " je prazno");\r
+               }\r
+\r
+               Osoba o2 = new Osoba("Krsta", "Krstic", 1988);\r
+               boolean ubacili = stablo.ubaci(o1, o2, true);\r
+               if (ubacili) {\r
+                       Svetovid.out.println("Uspesno smo ubacili " + o2 + ":");\r
+               } else {\r
+                       Svetovid.out.println("Nismo uspeli da ubacimo novu osobu");\r
+               }\r
+\r
+               BinarnoStablo<Osoba> roditelj = stablo.roditeljOd(o1);\r
+               if (roditelj != null) {\r
+                       Svetovid.out.println(o1 + " za roditelja ima " + roditelj);\r
+               } else {\r
+                       Svetovid.out.println(o1 + " nema roditelja");\r
+               }\r
+\r
+               BinarnoStablo<Osoba> kopija = stablo.kopija();\r
+               kopija.setLevoPodstablo(null);\r
+               BinarnoStablo<Osoba> obrnuto = stablo.obrnuto();\r
+               Svetovid.out.println();\r
+               Svetovid.out.println("Kopija stabla (sa odstranjenim levim podstablom):");\r
+               io.printStablo(Svetovid.out, kopija);\r
+               Svetovid.out.println();\r
+               Svetovid.out.println("Obrnuto stablo:");\r
+               io.printStablo(Svetovid.out, obrnuto);\r
+               Svetovid.out.println();\r
+               Svetovid.out.println("Originalno stablo:");\r
+               io.printStablo(Svetovid.out, stablo);\r
+\r
+               Svetovid.out.println();\r
+               Svetovid.out.println("Preorder:");\r
+               stablo.stampajPreorder();\r
+\r
+               Svetovid.out.println();\r
+               Svetovid.out.println("Inorder:");\r
+               stablo.stampajInorder();\r
+\r
+               Svetovid.out.println();\r
+               Svetovid.out.println("Postorder:");\r
+               stablo.stampajPostorder();\r
+\r
+               Svetovid.out.println();\r
+               Svetovid.out.println("Listovi:");\r
+               stablo.stampajListove();\r
+\r
+               Svetovid.out.println();\r
+               Svetovid.out.println("Svi ispod " + o1 + ":");\r
+               stablo.stampajSveIspod(o1);\r
+\r
+       }\r
+}\r
diff --git a/Stabla/StabloOpstegTipa/StabloIOPretty.java b/Stabla/StabloOpstegTipa/StabloIOPretty.java
new file mode 100644 (file)
index 0000000..8e286da
--- /dev/null
@@ -0,0 +1,223 @@
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
+\r
+import org.svetovid.io.SvetovidReader;\r
+import org.svetovid.io.SvetovidWriter;\r
+\r
+@interface DatoNaVezbama {}\r
+\r
+// Ako bude potrebna, ova klasa ce biti data na testu\r
+@DatoNaVezbama\r
+public class StabloIOPretty<T> {\r
+\r
+    protected static final String EMPTY_SYMBOL = " ";\r
+    protected static final String RIGHT_SYMBOL = "/";\r
+    protected static final String VERTICAL_SYMBOL = "|";\r
+    protected static final String LEFT_SYMBOL = "\\";\r
+    protected static final String HORIZONTAL_SYMBOL = "-";\r
+\r
+    protected Konverter<T> konverter;\r
+    protected String nullSymbol;\r
+    protected int separation;\r
+    protected int length;\r
+\r
+    public StabloIOPretty(Konverter<T> konverter) {\r
+        this(konverter, null, 1, 7);\r
+    }\r
+\r
+    public StabloIOPretty(Konverter<T> konverter, String nullSymbol, int separation, int length) {\r
+       this.konverter = konverter;\r
+        this.nullSymbol = nullSymbol;\r
+        this.separation = separation;\r
+        this.length = length;\r
+    }\r
+\r
+    public Konverter<T> getKonverter() {\r
+               return konverter;\r
+       }\r
+\r
+       public void setKonverter(Konverter<T> konverter) {\r
+               this.konverter = konverter;\r
+       }\r
+\r
+       public String getNullSymbol() {\r
+        return nullSymbol;\r
+    }\r
+\r
+    public void setNullSymbol(String nullSymbol) {\r
+        this.nullSymbol = nullSymbol;\r
+    }\r
+\r
+    public int getSeparation() {\r
+        return separation;\r
+    }\r
+\r
+    public void setSeparation(int separation) {\r
+        this.separation = separation;\r
+    }\r
+\r
+    public int getLength() {\r
+        return length;\r
+    }\r
+\r
+    public void setLength(int length) {\r
+        if (length < 3) {\r
+            throw new IllegalArgumentException("length");\r
+        }\r
+        this.length = length;\r
+    }\r
+\r
+    public BinarnoStablo<T> readStablo(SvetovidReader in) {\r
+        return parseStablo(in, konverter, nullSymbol, length);\r
+    }\r
+\r
+    protected BinarnoStablo<T> parseStablo(SvetovidReader in, Konverter<T> konverter, String nullSymbol, int length) {\r
+        List<BinarnoStablo<T>> elements = new ArrayList<>();\r
+        List<Integer> levels = new ArrayList<>();\r
+        Pattern levelPattern = Pattern.compile("[\\Q" + LEFT_SYMBOL + HORIZONTAL_SYMBOL + RIGHT_SYMBOL + "\\E]");\r
+        String line = in.readLine();\r
+        while ((line != null) && !line.isEmpty()) {\r
+            Matcher matcher = levelPattern.matcher(line);\r
+            int level = -1;\r
+            if (matcher.find()) {\r
+                level = matcher.start();\r
+            }\r
+            if (level != -1 && (nullSymbol == null || !line.endsWith(nullSymbol))) {\r
+               BinarnoStablo<T> stablo = parseStablo(konverter, line);\r
+                elements.add(stablo);\r
+                levels.add(level);\r
+            }\r
+            line = in.readLine();\r
+        }\r
+        BinarnoStablo<T> stablo = formStablo(0, elements.size(), levels, elements);\r
+        return stablo;\r
+    }\r
+\r
+    private BinarnoStablo<T> parseStablo(Konverter<T> konverter, String line) {\r
+        String vrednost;\r
+        int beginIndex = line.indexOf('(');\r
+        int endIndex = line.indexOf(')');\r
+        if ((beginIndex != -1) && (endIndex != -1) && (beginIndex < endIndex)) {\r
+            vrednost = line.substring(endIndex + 2);\r
+        } else {\r
+            throw new NumberFormatException(line);\r
+        }\r
+        T element = konverter.fromString(vrednost);\r
+        BinarnoStablo<T> stablo = new BinarnoStablo<>(element);\r
+        return stablo;\r
+    }\r
+\r
+    private BinarnoStablo<T> formStablo(int beginIndex, int endIndex, List<Integer> levels, List<BinarnoStablo<T>> elements) {\r
+        if (beginIndex >= endIndex) {\r
+            return null;\r
+        }\r
+        int minIndex = beginIndex;\r
+        int minLevel = levels.get(minIndex);\r
+        for (int i = beginIndex + 1; i < endIndex; i++) {\r
+            int level = levels.get(i);\r
+            if (level < minLevel) {\r
+                minLevel = level;\r
+                minIndex = i;\r
+            }\r
+        }\r
+        BinarnoStablo<T> stablo = elements.get(minIndex);\r
+        BinarnoStablo<T> levo = formStablo(minIndex + 1, endIndex, levels, elements);\r
+        BinarnoStablo<T> desno = formStablo(beginIndex, minIndex, levels, elements);\r
+        stablo.setLevoPodstablo(levo);\r
+        stablo.setDesnoPodstablo(desno);\r
+        return stablo;\r
+    }\r
+\r
+    public void printStablo(SvetovidWriter out, BinarnoStablo<T> stablo) {\r
+        StringBuilder builder = new StringBuilder();\r
+        appendTree(builder, stablo, konverter, nullSymbol, separation, length);\r
+        out.print(builder.toString());\r
+    }\r
+\r
+    protected void appendTree(StringBuilder builder, BinarnoStablo<T> stablo, Konverter<T> konverter, String nullSymbol, int separation, int length) {\r
+        String[] buildingBlocks = generateBuildingBlocks(length);\r
+        appendRight(builder, stablo, konverter, nullSymbol, separation, buildingBlocks, true, buildingBlocks[5]);\r
+        appendNode(builder, stablo, konverter, nullSymbol != null ? nullSymbol : "|", buildingBlocks[4]);\r
+        appendLeft(builder, stablo, konverter, nullSymbol, separation, buildingBlocks, false, buildingBlocks[5]);\r
+    }\r
+\r
+    protected void appendNode(StringBuilder builder, BinarnoStablo<T> stablo, Konverter<T> konverter, String nullSymbol, String prefix) {\r
+        builder.append(prefix);\r
+        if (stablo == null) {\r
+            builder.append(nullSymbol);\r
+        } else {\r
+            builder.append("(o) ");\r
+            String vrednost = konverter.toString(stablo.getElement());\r
+            builder.append(vrednost);\r
+        }\r
+        builder.append("\n");\r
+    }\r
+\r
+    protected void appendRight(StringBuilder builder, BinarnoStablo<T> stablo, Konverter<T> konverter, String nullSymbol, int separation, String[] buildingBlocks, boolean isRight, String prefix) {\r
+        if (stablo == null) {\r
+            return;\r
+        }\r
+        if ((nullSymbol != null) || (stablo.getDesnoPodstablo() != null)) {\r
+            appendSubtree(builder, stablo.getDesnoPodstablo(), konverter, nullSymbol, separation, buildingBlocks, true, prefix);\r
+            for (int i = 0; i < separation; i++) {\r
+                appendEmpty(builder, buildingBlocks, prefix);\r
+            }\r
+        }\r
+    }\r
+\r
+    protected void appendLeft(StringBuilder builder, BinarnoStablo<T> stablo, Konverter<T> konverter, String nullSymbol, int separation, String[] buildingBlocks, boolean isRight, String prefix) {\r
+        if (stablo == null) {\r
+            return;\r
+        }\r
+        if ((nullSymbol != null) || (stablo.getLevoPodstablo() != null)) {\r
+            for (int i = 0; i < separation; i++) {\r
+                appendEmpty(builder, buildingBlocks, prefix);\r
+            }\r
+            appendSubtree(builder, stablo.getLevoPodstablo(), konverter, nullSymbol, separation, buildingBlocks, false, prefix);\r
+        }\r
+    }\r
+\r
+    protected void appendEmpty(StringBuilder builder, String[] buildingBlocks, String prefix) {\r
+        builder.append(prefix);\r
+        builder.append(buildingBlocks[2]);\r
+        builder.append("\n");\r
+    }\r
+\r
+    protected void appendSubtree(StringBuilder builder, BinarnoStablo<T> stablo, Konverter<T> konverter, String nullSymbol, int separation, String[] buildingBlocks, boolean isRight, String prefix) {\r
+        String mojPrefix = prefix;\r
+        if (isRight == true) {\r
+            mojPrefix = mojPrefix + buildingBlocks[1];\r
+        }\r
+        if (isRight == false) {\r
+            mojPrefix = mojPrefix + buildingBlocks[3];\r
+        }\r
+        String noviPrefix = prefix + (!isRight ? buildingBlocks[2] : buildingBlocks[0]);\r
+        appendRight(builder, stablo, konverter, nullSymbol, separation, buildingBlocks, isRight, noviPrefix);\r
+        appendNode(builder, stablo, konverter, nullSymbol, mojPrefix);\r
+        noviPrefix = prefix + (isRight ? buildingBlocks[2] : buildingBlocks[0]);\r
+        appendLeft(builder, stablo, konverter, nullSymbol, separation, buildingBlocks, isRight, noviPrefix);\r
+    }\r
+\r
+    private String[] generateBuildingBlocks(int length) {\r
+        String[] blocks = new String[6];\r
+        blocks[0] = generateBlock(EMPTY_SYMBOL, EMPTY_SYMBOL, EMPTY_SYMBOL, length - 2);\r
+        blocks[1] = generateBlock(EMPTY_SYMBOL, RIGHT_SYMBOL, HORIZONTAL_SYMBOL, length - 2);\r
+        blocks[2] = generateBlock(EMPTY_SYMBOL, VERTICAL_SYMBOL, EMPTY_SYMBOL, length - 2);\r
+        blocks[3] = generateBlock(EMPTY_SYMBOL, LEFT_SYMBOL, HORIZONTAL_SYMBOL, length - 2);\r
+        blocks[4] = HORIZONTAL_SYMBOL;\r
+        blocks[5] = EMPTY_SYMBOL;\r
+        return blocks;\r
+    }\r
+\r
+    protected String generateBlock(String emptySymbol, String startSymbol, String repeatSymbol, int repeatCount) {\r
+        StringBuilder builder = new StringBuilder();\r
+        builder.append(emptySymbol);\r
+        builder.append(startSymbol);\r
+        for (int i = 0; i < repeatCount; i++) {\r
+            builder.append(repeatSymbol);\r
+        }\r
+        return builder.toString();\r
+    }\r
+}\r
diff --git a/Stabla/StabloOpstegTipa/StabloProgram.java b/Stabla/StabloOpstegTipa/StabloProgram.java
new file mode 100644 (file)
index 0000000..2594334
--- /dev/null
@@ -0,0 +1,167 @@
+import java.util.NoSuchElementException;\r
+//@interface DatoNaVezbama {}\r
+\r
+// Tip podataka koji sadrzi binarno stablo\r
+class BinarnoStablo<T> {\r
+\r
+       // Tip podataka koji opisuje jedan cvor stabla\r
+       private static class Cvor<T> {\r
+               \r
+               T element;\r
+               Cvor<T> levo;\r
+               Cvor<T> desno;\r
+\r
+               Cvor(T element, Cvor<T> levo, Cvor<T> desno) {\r
+                       this.element = element;\r
+                       this.levo = levo;\r
+                       this.desno = desno;\r
+               }\r
+       }\r
+\r
+       // Cvor koji je koren stabla\r
+       // Ako je stablo prazno, koren je null\r
+       protected Cvor<T> koren;\r
+\r
+       // Kreiramo prazno stablo\r
+       public BinarnoStablo() {\r
+               koren = null;\r
+       }\r
+\r
+       // Kreiramo stablo sa datim elementom u korenu\r
+       // bez levog i desnog podstabla\r
+       public BinarnoStablo(T element) {\r
+               koren = new Cvor<>(element, null, null);\r
+       }\r
+\r
+       // Kreiramo novo stablo sa datim elementom u korenu\r
+       // i datim levim i desnim podstablom\r
+       public BinarnoStablo(T element, BinarnoStablo<T> levo, BinarnoStablo<T> desno) {\r
+               koren = new Cvor<T>(element, levo.koren, desno.koren);\r
+       }\r
+\r
+       // Zasticeni konstruktor za kreiranje novog stabla\r
+       // sa korenom u datom cvoru ovog stabla\r
+       protected BinarnoStablo(Cvor<T> koren) {\r
+               this.koren = koren;\r
+       }\r
+\r
+       public T getElement() {\r
+               if (koren == null) { // Stablo je prazno\r
+                       throw new NoSuchElementException();\r
+               }\r
+               return koren.element;\r
+       }\r
+\r
+       public void setElement(T element) {\r
+               if (koren == null) { // Stablo je prazno\r
+                       throw new NoSuchElementException();\r
+               }\r
+               koren.element = element;\r
+       }\r
+\r
+       public BinarnoStablo<T> getLevoPodstablo() {\r
+               if (koren == null) { // Stablo je prazno\r
+                       throw new NoSuchElementException();\r
+               }\r
+               if (koren.levo == null) { // Nema levog podstabla\r
+                       return null;\r
+               }\r
+               return new BinarnoStablo<T>(koren.levo);\r
+       }\r
+\r
+       public void setLevoPodstablo(BinarnoStablo<T> levo) {\r
+               if (koren == null) { // Stablo je prazno\r
+                       throw new NoSuchElementException();\r
+               }\r
+               if (levo == null) {\r
+                       koren.levo = null;\r
+               } else {\r
+                       koren.levo = levo.koren;\r
+               }\r
+       }\r
+\r
+       public BinarnoStablo<T> getDesnoPodstablo() {\r
+               if (koren == null) { // Stablo je prazno\r
+                       throw new NoSuchElementException();\r
+               }\r
+               if (koren.desno == null) {\r
+                       return null;\r
+               }\r
+               return new BinarnoStablo<T>(koren.desno);\r
+       }\r
+\r
+       public void setDesnoPodstablo(BinarnoStablo<T> desno) {\r
+               if (koren == null) { // Stablo je prazno\r
+                       throw new NoSuchElementException();\r
+               }\r
+               if (desno == null) {\r
+                       koren.desno = null;\r
+               } else {\r
+                       koren.desno = desno.koren;\r
+               }\r
+       }\r
+\r
+//    @DatoNaVezbama\r
+       public int brojElemenata() {\r
+       // Spremimo argumente i pozovemo rekurzivni metod\r
+       return brojElemenata(koren);\r
+       }\r
+\r
+  //  @DatoNaVezbama\r
+    // Metod koji zapravo resava dati problem\r
+    protected static <T> int brojElemenata(Cvor<T> cvor) {\r
+       if (cvor == null) {\r
+               return 0;\r
+       }\r
+               int broj = 1;\r
+               broj = broj + brojElemenata(cvor.levo);\r
+               broj = broj + brojElemenata(cvor.desno);\r
+               return broj;\r
+    }\r
+\r
+ //   @DatoNaVezbama\r
+       public int brojNivoa() {\r
+       // Spremimo argumente i pozovemo rekurzivni metod\r
+       return brojNivoa(koren);\r
+       }\r
+\r
+   @DatoNaVezbama\r
+    // Metod koji zapravo resava dati problem\r
+       protected static int brojNivoa(Cvor cvor) {\r
+       if (cvor == null) {\r
+               return 0;\r
+       }\r
+               int brojNivoaLevog = brojNivoa(cvor.levo);\r
+               int brojNivoaDesnog = brojNivoa(cvor.desno);\r
+               return Math.max(brojNivoaLevog, brojNivoaDesnog) + 1;\r
+       }\r
+}\r
+\r
+// Glavna klasa\r
+public class StabloProgram {\r
+\r
+       // Glavni program\r
+       public static void main(String[] args) {\r
+\r
+               // Kreiramo objekat koji koristimo za ucitavanje i ispisivanje stabla\r
+               StabloIOPretty<Osoba> io = new StabloIOPretty<>(Konverter.OSOBA);\r
+\r
+               // Ucitamo stablo\r
+               BinarnoStablo<Osoba> stablo = io.readStablo(Svetovid.in("Osobe.txt"));\r
+\r
+               // Ispisemo ucitano stablo na ekran\r
+               io.printStablo(Svetovid.out, stablo);\r
+               Svetovid.out.println();\r
+\r
+               // Ilustrujemo poziv metoda\r
+               \r
+               int brojElemenata = stablo.brojElemenata();\r
+               Svetovid.out.println("Broj elemenata:", brojElemenata);\r
+               \r
+               int brojNivoa = stablo.brojNivoa();\r
+               Svetovid.out.println("Broj nivoa:", brojNivoa);\r
+\r
+               // TODO Dodati pozive ostalih metoda\r
+\r
+       }\r
+}\r
diff --git a/Stabla/StabloOpstegTipa/_zadatak-stabla.txt b/Stabla/StabloOpstegTipa/_zadatak-stabla.txt
new file mode 100644 (file)
index 0000000..b271547
--- /dev/null
@@ -0,0 +1,142 @@
+************************************************************\r
+         Zadatak - binarna stabla\r
+************************************************************\r
+\r
+Data je klasa BinarnoStablo koja implementira opste binarno\r
+stablo. Takodje je dat i glavni program koji ucitava jedno\r
+stablo i poziva neke od operacija nad njim.\r
+\r
+Implementirati operacije navedene u nastavku i ilustrovati\r
+njihov rad pozivanjem iz glavnog programa. Svaki metod je\r
+potrebno implementirati kao javan metod klase BinarnoStablo,\r
+uz pomocni zasticen staticki metod istog imena. Pogledati\r
+primer implementacije metoda brojElemenata() i brojNivoa().\r
+\r
+Sve promene treba raditi u fajlu StabloProgram.java u kome\r
+su pomenute klase. Ostali fajlovi su klasa Osoba koja\r
+predstavlja element koji ubacujemo u konkretnom programu,\r
+kao i pomocne klase koje sluze za ucitavanje stabla iz fajla\r
+u urednom formatu. Ucitavanje stabla na ovaj nacin nije\r
+neophodno uciti.\r
+\r
+\r
+Metodi\r
+======\r
+\r
+public boolean jePrazno()\r
+-------------------------\r
+\r
+U klasi BinarnoStablo, implementirati metod koji\r
+vraca true ako je stablo prazno, false ako nije.\r
+\r
+public boolean postojiElement(T element)\r
+----------------------------------------\r
+\r
+U klasi BinarnoStablo, implementirati metod koji\r
+vraca true ako se prosledjeni elemnt nalazi u\r
+stablu, false inace.\r
+\r
+Prilikom pretrage stabla koristiti metod equals().\r
+\r
+\r
+public void stampajPreorder()\r
+----------------------------\r
+\r
+U klasi BinarnoStablo, implementirati metod koji\r
+stampa sve elemente preorder nacinom obilaska.\r
+\r
+public void stampajInOrder()\r
+----------------------------\r
+\r
+U klasi BinarnoStablo, implementirati metod koji\r
+stampa sve elemente inorder nacinom obilaska.\r
+\r
+public void stampajPostOrder()\r
+----------------------------\r
+\r
+U klasi BinarnoStablo, implementirati metod koji\r
+stampa sve elemente postorder nacinom obilaska.\r
+\r
+public void stampajListove()\r
+----------------------------\r
+\r
+U klasi BinarnoStablo, implementirati metod koji\r
+stampa sve elemente koji se nalaze u listovima.\r
+\r
+List je cvor koji nema ni levog ni desnog potomka.\r
+\r
+private Cvor<T> pronadji(T element)\r
+------------------------------------\r
+\r
+U klasi BinarnoStablo, implementirati metod koji\r
+pronalazi dati element i vraca stablo sa korenom\r
+u tom elementu.\r
+\r
+Ako element ne postoji u stablu, vratiti null.\r
+\r
+Ovaj metod koristiti kao pomocni za sledeci.\r
+\r
+\r
+public void stampajSveIspod(T element)\r
+--------------------------------------\r
+\r
+U klasi BinarnoStablo, implementirati metod koji\r
+stampa sve elemnte koji su direktni ili indirektni\r
+potomci datog.\r
+\r
+\r
+public boolean ubaci(T roditelj, T potomak, boolean levo)\r
+---------------------------------------------------------\r
+\r
+U klasi BinarnoStablo, implementirati metod koji\r
+pronalazi element dat u prvom argumentu (roditelj)\r
+i kao njegovog poromka ubacuje element dat u drugom\r
+argumentu (potomak). Ako je treci argument (levo)\r
+true tada se element ubacuje kao levi potomak, a\r
+ako je false, kao desni.\r
+\r
+Ako se na zeljenom mestu vec nalazi nesto, vratiti false\r
+i ne ubacivati element, inace vratiti true pri uspesnom\r
+ubacivanju.\r
+\r
+\r
+public T roditeljOd(T potomak)\r
+--------------------------------------\r
+\r
+U klasi BinarnoStablo, implementirati metod koji\r
+pronalazi i vraca roditelja datog elementa. Ako\r
+je prosledjeni element koren celog stabla\r
+vratiti null.\r
+\r
+public T min(Comparator<T> komparator)\r
+public T max(Comparator<T> komparator)\r
+--------------------------------------\r
+\r
+U klasi BinarnoStablo, implementirati metod koji\r
+pronalazi i vraca najmanji, odnosno najveci, element\r
+stabla.\r
+\r
+Prilikom pretrage koristiti prosledjeni komparator.\r
+\r
+\r
+public BinarnoStablo<T> kopija()\r
+-------------------------\r
+\r
+U klasi BinarnoStablo, implementirati metod koji\r
+vraca kopiju stabla.\r
+\r
+Potrebno je iskopirati i sve cvorove kako izmene\r
+jednog stabla ne bi uticale na drugo.\r
+\r
+\r
+public BinarnoStablo<T> obrnuto()\r
+--------------------------\r
+\r
+U klasi BinarnoStablo, implementirati metod koji\r
+vraca novo stablo nastalo obrtanjem originalng.\r
+Stablo se obrce tako sto se zamene mesta levih\r
+i desnih podstabala koja se pre toga takogje\r
+obrnu.\r
+\r
+Posle poziva metoda originalno stablo mora ostati\r
+nepromenjeno.\r
Svarog.pmf.uns.ac.rs/gitweb maintanance Doni Pracner