gitweb on Svarog
projekti pod git sistemom za održavanje verzija -- projects under the git version control system
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5724370)
raw | patch | inline | side by side (parent: 5724370)
author | Doni Pracner <quinnuendo@gmail.com> | |
Sat, 19 Dec 2015 15:40:53 +0000 (16:40 +0100) | ||
committer | Doni Pracner <quinnuendo@gmail.com> | |
Sat, 19 Dec 2015 15:40:53 +0000 (16:40 +0100) |
Stabla/Primeri za test/StabloIO.java | [deleted file] | patch | blob | history |
Stabla/Primeri za test/StabloIOClassic.java | [deleted file] | patch | blob | history |
Stabla/Primeri za test/StabloIOIndent.java | [deleted file] | patch | blob | history |
Stabla/Primeri za test/StabloIOPretty.java | [deleted file] | patch | blob | history |
Stabla/Primeri za test/StabloIORandom.java | [deleted file] | patch | blob | history |
Stabla/Primeri za test/StabloProgram.java | [deleted file] | patch | blob | history |
Stabla/Primeri za test/classic.txt | [deleted file] | patch | blob | history |
Stabla/Primeri za test/indent.txt | [deleted file] | patch | blob | history |
Stabla/Primeri za test/pretty.txt | [deleted file] | patch | blob | history |
diff --git a/Stabla/Primeri za test/StabloIO.java b/Stabla/Primeri za test/StabloIO.java
+++ /dev/null
@@ -1,14 +0,0 @@
-import org.svetovid.io.SvetovidReader;\r
-import org.svetovid.io.SvetovidWriter;\r
-\r
-/*\r
- * Ovaj interfejs i klase koje ga implementiraju sluze za ucitavanje i\r
- * snimanje stabala. Nije potrebno znati ih, i bice dati, prilikom izrade\r
- * prakticnih zadataka.\r
- */\r
-public interface StabloIO {\r
-\r
- public Stablo readStablo(SvetovidReader in);\r
- public void printStablo(SvetovidWriter out, Stablo stablo);\r
-\r
-}\r
diff --git a/Stabla/Primeri za test/StabloIOClassic.java b/Stabla/Primeri za test/StabloIOClassic.java
+++ /dev/null
@@ -1,90 +0,0 @@
-import java.util.NoSuchElementException;\r
-\r
-import org.svetovid.io.SvetovidReader;\r
-import org.svetovid.io.SvetovidWriter;\r
-\r
-/*\r
- * Ova klasa sluzi za ucitavanje i snimanje stabala. Nije potrebno znati je,\r
- * i bice data, prilikom izrade prakticnih zadataka.\r
- *\r
- * Ocekivani format fajla je sledeci:\r
- *\r
- * br\r
- * id leviId desniId vrednost (x br)\r
- *\r
- * Primer fajla je classic.txt\r
- */\r
-public class StabloIOClassic implements StabloIO {\r
-\r
- @Override\r
- public Stablo readStablo(SvetovidReader in) {\r
- int br = in.readInt();\r
- Stablo stablo = null;\r
- for (int i = 0; i < br; i++) {\r
- int id = in.readInt();\r
- int leviId = in.readInt();\r
- int desniId = in.readInt();\r
- String vrednost = in.readLine();\r
- Stablo levi = leviId == -1 ? null : new Stablo(leviId);\r
- Stablo desni =desniId == -1 ? null : new Stablo(desniId);\r
- Stablo element = new Stablo(id, vrednost, levi, desni);\r
- stablo = insert(stablo, element);\r
- }\r
- return stablo;\r
- }\r
-\r
- private static Stablo insert(Stablo stablo, Stablo element) {\r
- if (stablo == null) {\r
- return element;\r
- }\r
- Stablo found = find(stablo, element.getId());\r
- if (found == null) {\r
- throw new NoSuchElementException("id: " + element.getId());\r
- }\r
- found.setVrednost(element.getVrednost());\r
- found.setLevi(element.getLevi());\r
- found.setDesni(element.getDesni());\r
- return stablo;\r
- }\r
-\r
- private static Stablo find(Stablo stablo, int id) {\r
- if (stablo == null) {\r
- return null;\r
- }\r
- if (stablo.getId() == id) {\r
- return stablo;\r
- }\r
- Stablo rezultat = find(stablo.getLevi(), id);\r
- if (rezultat != null) {\r
- return rezultat;\r
- }\r
- return find(stablo.getDesni(), id);\r
- }\r
-\r
- @Override\r
- public void printStablo(SvetovidWriter out, Stablo stablo) {\r
- int br = count(stablo);\r
- out.println(br);\r
- iterate(out, stablo);\r
- }\r
-\r
- private static int count(Stablo stablo) {\r
- if (stablo == null) {\r
- return 0;\r
- }\r
- return 1 + count(stablo.getLevi()) + count(stablo.getDesni());\r
- }\r
-\r
- private static void iterate(SvetovidWriter out, Stablo stablo) {\r
- if (stablo == null) {\r
- return;\r
- }\r
- int id = stablo.getId();\r
- int leviId = stablo.getLevi() == null ? -1 : stablo.getLevi().getId();\r
- int desniId = stablo.getDesni() == null ? -1 : stablo.getDesni().getId();\r
- String vrednost = stablo.getVrednost();\r
- out.println(id, leviId, desniId, vrednost);\r
- iterate(out, stablo.getLevi());\r
- iterate(out, stablo.getDesni());\r
- }\r
-}\r
diff --git a/Stabla/Primeri za test/StabloIOIndent.java b/Stabla/Primeri za test/StabloIOIndent.java
+++ /dev/null
@@ -1,78 +0,0 @@
-import org.svetovid.SvetovidFormatException;\r
-import org.svetovid.io.SvetovidReader;\r
-import org.svetovid.io.SvetovidWriter;\r
-\r
-/*\r
- * Ova klasa sluzi za ucitavanje i snimanje stabala. Nije potrebno znati je,\r
- * i bice data, prilikom izrade prakticnih zadataka.\r
- *\r
- * Ocekivani format fajla je sledeci:\r
- *\r
- * id vrednost\r
- * levi\r
- * desni\r
- *\r
- * Primer fajla je indent.txt\r
- */\r
-public class StabloIOIndent implements StabloIO {\r
-\r
- protected String nullSymbol;\r
- protected String indent;\r
-\r
- public StabloIOIndent() {\r
- this("-", " ");\r
- }\r
-\r
- public StabloIOIndent(String nullSymbol, String indent) {\r
- this.nullSymbol = nullSymbol;\r
- this.indent = indent;\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 String getIndent() {\r
- return indent;\r
- }\r
-\r
- public void setIndent(String indent) {\r
- this.indent = indent;\r
- }\r
-\r
- @Override\r
- public Stablo readStablo(SvetovidReader in) {\r
- try {\r
- int id = in.readInt();\r
- String vrednost = in.readLine();\r
- Stablo levi = readStablo(in);\r
- Stablo desni = readStablo(in);\r
- Stablo stablo = new Stablo(id, vrednost, levi, desni);\r
- return stablo;\r
- } catch (SvetovidFormatException e) {\r
- return null;\r
- }\r
- }\r
-\r
- @Override\r
- public void printStablo(SvetovidWriter out, Stablo stablo) {\r
- write(out, stablo, nullSymbol, indent, "");\r
- }\r
-\r
- protected void write(SvetovidWriter out, Stablo stablo, String nullSymbol, String indent, String prefix) {\r
- if (stablo == null) {\r
- out.println(prefix + nullSymbol);\r
- return;\r
- }\r
- int id = stablo.getId();\r
- String vrednost = stablo.getVrednost();\r
- out.print(prefix);\r
- out.println(id, vrednost);\r
- write(out, stablo.getLevi(), nullSymbol, indent, prefix + indent);\r
- write(out, stablo.getDesni(), nullSymbol, indent, prefix + indent);\r
- }\r
-}\r
diff --git a/Stabla/Primeri za test/StabloIOPretty.java b/Stabla/Primeri za test/StabloIOPretty.java
+++ /dev/null
@@ -1,230 +0,0 @@
-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
-/*\r
- * Ova klasa sluzi za ucitavanje i snimanje stabala. Nije potrebno znati je,\r
- * i bice data, prilikom izrade prakticnih zadataka.\r
- *\r
- * Ocekivani format fajla je sledeci:\r
- *\r
- * /-- desni\r
- * -(id) vrednost\r
- * \-- levi\r
- *\r
- * Primer fajla je pretty.txt\r
- */\r
-public class StabloIOPretty implements StabloIO {\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 String nullSymbol;\r
- protected boolean separated;\r
- protected int length;\r
-\r
- public StabloIOPretty() {\r
- this(null, false, 7);\r
- }\r
-\r
- public StabloIOPretty(String nullSymbol, boolean separated, int length) {\r
- this.nullSymbol = nullSymbol;\r
- this.separated = separated;\r
- this.length = length;\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 boolean isSeparated() {\r
- return separated;\r
- }\r
-\r
- public void setSeparated(boolean separated) {\r
- this.separated = separated;\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
- @Override\r
- public Stablo readStablo(SvetovidReader in) {\r
- return parseStablo(in, nullSymbol, length);\r
- }\r
-\r
- protected Stablo parseStablo(SvetovidReader in, String nullSymbol, int length) {\r
- List<Stablo> 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
- Stablo stablo = parseStablo(line);\r
- elements.add(stablo);\r
- levels.add(level);\r
- }\r
- line = in.readLine();\r
- }\r
- Stablo stablo = formStablo(0, elements.size(), levels, elements);\r
- return stablo;\r
- }\r
-\r
- private Stablo parseStablo(String line) {\r
- int id = -1;\r
- String vrednost = null;\r
- int beginIndex = line.indexOf('(');\r
- int endIndex = line.indexOf(')');\r
- if ((beginIndex != -1) && (endIndex != -1) && (beginIndex < endIndex)) {\r
- vrednost = line.substring(beginIndex + 1, endIndex);\r
- try {\r
- id = Integer.parseInt(vrednost);\r
- } catch (NumberFormatException e) {\r
- throw new NumberFormatException(line);\r
- }\r
- vrednost = line.substring(endIndex + 2);\r
- } else {\r
- throw new NumberFormatException(line);\r
- }\r
- Stablo stablo = new Stablo(id, vrednost);\r
- return stablo;\r
- }\r
-\r
- private Stablo formStablo(int beginIndex, int endIndex, List<Integer> levels, List<Stablo> 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
- Stablo stablo = elements.get(minIndex);\r
- Stablo levi = formStablo(minIndex + 1, endIndex, levels, elements);\r
- Stablo desni = formStablo(beginIndex, minIndex, levels, elements);\r
- stablo.setLevi(levi);\r
- stablo.setDesni(desni);\r
- return stablo;\r
- }\r
-\r
- @Override\r
- public void printStablo(SvetovidWriter out, Stablo stablo) {\r
- StringBuilder builder = new StringBuilder();\r
- appendTree(builder, stablo, nullSymbol, separated, length);\r
- out.print(builder.toString());\r
- }\r
-\r
- protected void appendTree(StringBuilder builder, Stablo stablo, String nullSymbol, boolean separated, int length) {\r
- String[] buildingBlocks = generateBuildingBlocks(length);\r
- appendRight(builder, stablo, nullSymbol, separated, buildingBlocks, true, buildingBlocks[5]);\r
- appendNode(builder, stablo, nullSymbol != null ? nullSymbol : "|", buildingBlocks[4]);\r
- appendLeft(builder, stablo, nullSymbol, separated, buildingBlocks, false, buildingBlocks[5]);\r
- }\r
-\r
- protected void appendNode(StringBuilder builder, Stablo stablo, String nullSymbol, String prefix) {\r
- builder.append(prefix);\r
- if (stablo == null) {\r
- builder.append(nullSymbol);\r
- } else {\r
- builder.append("(");\r
- builder.append(stablo.getId());\r
- builder.append(") ");\r
- builder.append(stablo.getVrednost());\r
- }\r
- builder.append("\n");\r
- }\r
-\r
- protected void appendRight(StringBuilder builder, Stablo stablo, String nullSymbol, boolean separated, String[] buildingBlocks, boolean isRight, String prefix) {\r
- if (stablo == null) {\r
- return;\r
- }\r
- if ((nullSymbol != null) || (stablo.getDesni() != null)) {\r
- appendSubtree(builder, stablo.getDesni(), nullSymbol, separated, buildingBlocks, true, prefix);\r
- if (separated) {\r
- appendEmpty(builder, buildingBlocks, prefix);\r
- }\r
- }\r
- }\r
-\r
- protected void appendLeft(StringBuilder builder, Stablo stablo, String nullSymbol, boolean separated, String[] buildingBlocks, boolean isRight, String prefix) {\r
- if (stablo == null) {\r
- return;\r
- }\r
- if ((nullSymbol != null) || (stablo.getLevi() != null)) {\r
- if (separated) {\r
- appendEmpty(builder, buildingBlocks, prefix);\r
- }\r
- appendSubtree(builder, stablo.getLevi(), nullSymbol, separated, 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, Stablo stablo, String nullSymbol, boolean separated, 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, nullSymbol, separated, buildingBlocks, isRight, noviPrefix);\r
- appendNode(builder, stablo, nullSymbol, mojPrefix);\r
- noviPrefix = prefix + (isRight ? buildingBlocks[2] : buildingBlocks[0]);\r
- appendLeft(builder, stablo, nullSymbol, separated, 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/Primeri za test/StabloIORandom.java b/Stabla/Primeri za test/StabloIORandom.java
+++ /dev/null
@@ -1,79 +0,0 @@
-import java.math.BigInteger;\r
-import java.util.Random;\r
-import java.util.concurrent.atomic.AtomicInteger;\r
-\r
-import org.svetovid.io.SvetovidReader;\r
-import org.svetovid.io.SvetovidWriter;\r
-\r
-/*\r
- * Ova klasa sluzi za generisanje random stabala. Nije potrebno znati je,\r
- * i bice data, prilikom izrade prakticnih zadataka.\r
- */\r
-public class StabloIORandom implements StabloIO {\r
-\r
- protected long seed;\r
- protected int length;\r
- protected int depth;\r
-\r
- public StabloIORandom() {\r
- this(System.currentTimeMillis());\r
- }\r
-\r
- public StabloIORandom(long seed) {\r
- this(seed, 5, 10);\r
- }\r
-\r
- public StabloIORandom(long seed, int length, int depth) {\r
- this.seed = seed;\r
- this.length = length;\r
- this.depth = depth;\r
- }\r
-\r
- public long getSeed() {\r
- return seed;\r
- }\r
-\r
- public void setSeed(long seed) {\r
- this.seed = seed;\r
- }\r
-\r
- public int getLength() {\r
- return length;\r
- }\r
-\r
- public void setLength(int length) {\r
- this.length = length;\r
- }\r
-\r
- public int getDepth() {\r
- return depth;\r
- }\r
-\r
- public void setDepth(int depth) {\r
- this.depth = depth;\r
- }\r
-\r
- @Override\r
- public Stablo readStablo(SvetovidReader in) {\r
- Random random = new Random(seed);\r
- AtomicInteger sequence = new AtomicInteger();\r
- Stablo stablo = readStablo(random, sequence, length, depth);\r
- return stablo;\r
- }\r
-\r
- private Stablo readStablo(Random random, AtomicInteger sequence, int length, int depth) {\r
- if (depth <= 0) {\r
- return null;\r
- }\r
- int id = sequence.addAndGet(1 + random.nextInt(9));\r
- String vrednost = new BigInteger(length, random).toString(36);\r
- Stablo desni = readStablo(random, sequence, length + random.nextInt(5), depth - random.nextInt(5));\r
- Stablo levi = readStablo(random, sequence, length + random.nextInt(5), depth - random.nextInt(5));\r
- return new Stablo(id, vrednost, levi, desni);\r
- }\r
-\r
- @Override\r
- public void printStablo(SvetovidWriter out, Stablo stablo) {\r
- throw new UnsupportedOperationException();\r
- }\r
-}\r
diff --git a/Stabla/Primeri za test/StabloProgram.java b/Stabla/Primeri za test/StabloProgram.java
+++ /dev/null
@@ -1,242 +0,0 @@
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.Objects;\r
-\r
-// Tip podataka koji predstavlja binarno stablo\r
-// ID svakog cvora je tipa int a vrednost sadrzana u njemu tipa String\r
-// Na velikom testu, studenti ce dobiti ovu klasu\r
-class Stablo {\r
-\r
- private final int id;\r
- private String vrednost;\r
- private Stablo levi;\r
- private Stablo desni;\r
-\r
- public Stablo(int id) {\r
- this(id, null);\r
- }\r
-\r
- public Stablo(int id, String vrednost) {\r
- this(id, vrednost, null, null);\r
- }\r
-\r
- public Stablo(int id, String vrednost, Stablo levi, Stablo desni) {\r
- this.id = id;\r
- this.vrednost = vrednost;\r
- this.levi = levi;\r
- this.desni = desni;\r
- }\r
-\r
- public int getId() {\r
- return id;\r
- }\r
-\r
- public String getVrednost() {\r
- return vrednost;\r
- }\r
-\r
- public void setVrednost(String vrednost) {\r
- this.vrednost = vrednost;\r
- }\r
-\r
- public Stablo getLevi() {\r
- return levi;\r
- }\r
-\r
- public void setLevi(Stablo levi) {\r
- this.levi = levi;\r
- }\r
-\r
- public Stablo getDesni() {\r
- return desni;\r
- }\r
-\r
- public void setDesni(Stablo desni) {\r
- this.desni = desni;\r
- }\r
-\r
- @Override\r
- public String toString() {\r
- return "(" + id + " \"" + vrednost + "\"" + (levi == null ? "" : " " + levi) + (desni == null ? "" : " " + desni) + ")";\r
- }\r
-\r
- @Override\r
- public int hashCode() {\r
- final int prostBroj = 31;\r
- int rezultat = 1;\r
- rezultat = rezultat * prostBroj + id;\r
- rezultat = rezultat * prostBroj + ((vrednost == null) ? 0 : vrednost.hashCode());\r
- rezultat = rezultat * prostBroj + ((levi == null) ? 0 : levi.hashCode());\r
- rezultat = rezultat * prostBroj + ((desni == null) ? 0 : desni.hashCode());\r
- return rezultat;\r
- }\r
-\r
- @Override\r
- public boolean equals(Object obj) {\r
-\r
- // Objekat je jednak ako je identican\r
- if (this == obj) {\r
- return true;\r
- }\r
-\r
- // Null je razlicit od svih objekata\r
- if (obj == null) {\r
- return false;\r
- }\r
-\r
- // Ako su klase objekata razlicite, onda su i objekti razliciti\r
- if (getClass() != obj.getClass()) {\r
- return false;\r
- }\r
-\r
- // Pretvorimo prosledjeni objekat u stablo\r
- Stablo that = (Stablo) obj;\r
-\r
- // Razlicit ID znaci da su objekti razliciti\r
- if (this.id != that.id) {\r
- return false;\r
- }\r
-\r
- // Takodje i vrednost\r
- if (Objects.equals(this.vrednost, that.vrednost)) {\r
- return false;\r
- }\r
-\r
- // Potom levo podstablo\r
- if (Objects.equals(this.levi, that.levi)) {\r
- return false;\r
- }\r
-\r
- // Pa desno podstablo\r
- if (Objects.equals(this.desni, that.desni)) {\r
- return false;\r
- }\r
-\r
- // Sva polja se poklapaju\r
- return true;\r
-\r
- }\r
-}\r
-\r
-// Glavni program\r
-// Na velikom testu ce biti dat kostur koji ucitava potrebno stablo\r
-// Od studenata ce se ocekivati da implementiraju neki algoritam poput\r
-// statickih metoda koje se pozivaju u ovoj klasi\r
-public class StabloProgram {\r
-\r
- public static void main(String[] args) {\r
-\r
- // Ucitavanje stabla iz fajla u "pretty" formatu\r
- // StabloIO inIO = new StabloIOPretty();\r
- // Stablo stablo = inIO.readStablo(Svetovid.in("pretty.txt"));\r
-\r
- // Generisanje random stabla\r
- StabloIO inIO = new StabloIORandom(12345);\r
- Stablo stablo = inIO.readStablo(null);\r
-\r
- // Ispisivanje stabla na ekran\r
- StabloIO outIO = new StabloIOPretty();\r
- outIO.printStablo(Svetovid.out, stablo);\r
- Svetovid.out.println();\r
-\r
- // Broj nivoa\r
- int brojNivoa = brojNivoa(stablo);\r
- Svetovid.out.println("Broj nivoa:", brojNivoa);\r
- Svetovid.out.println();\r
-\r
- // Broj elemenata\r
- int brojElementata = brojElementata(stablo);\r
- Svetovid.out.println("Broj elementata:", brojElementata);\r
- Svetovid.out.println();\r
-\r
- // Najduza String vrednost u stablu\r
- String najduzaVrednost = najduzaVrednost(stablo);\r
- Svetovid.out.println("Najduza vrednost:", najduzaVrednost);\r
- Svetovid.out.println();\r
-\r
- // Svi Putevi od korena do listova\r
- sviPutevi(stablo, new ArrayList<>(brojNivoa));\r
- Svetovid.out.println();\r
-\r
- // Obrnuto stablo\r
- Stablo obrnuto = obrni(stablo);\r
- outIO.printStablo(Svetovid.out, obrnuto);\r
- Svetovid.out.println();\r
-\r
- // Implementacije ovih algoritama su date ispod kao staticki metodi\r
- // Za veliki test, od studenata ce se ocekivati da na isti nacin\r
- // implementiraju algoritam koji se bude trazio u zadatku.\r
- //\r
- // Pored ovde implementiranih algoritama, sledi i par ideja za vezbanje:\r
- // - Ispisati vrednosti cvorova sa parnim IDom\r
- // - Ispisati sve vrednosti cvorova na nivou koji se ucitava sa tastature\r
- // - Utvrditi da li postoji postoji putanja od korena do lista koja sadrzi\r
- // string duzine 5\r
- // - Napraviti novo stablo iste strukture ali sa svim vrednostima ALL CAPS\r
- // - Proveriti da li je dato stablo binarno stablo pretrazivanj, tj. da\r
- // su sve vrednosti u levom podstablu leksikografski pre vrednosti u\r
- // korenu, svi elementi u desnom leksikografski posle, i ovo takodje\r
- // vazi za oba podstabla\r
- // - Koliko ima cvorova na nivou 7\r
- // - Koliko se puta string "abc" javlja u stablu\r
-\r
- }\r
-\r
- // Vraca ukupan broj elemenata u stablu\r
- private static int brojElementata(Stablo stablo) {\r
- if (stablo == null) {\r
- return 0; // Prazno stablo ima 0 elemenata\r
- }\r
- return 1 + brojElementata(stablo.getLevi()) + brojElementata(stablo.getDesni());\r
- }\r
-\r
- // Vraca visinu stabla\r
- private static int brojNivoa(Stablo stablo) {\r
- if (stablo == null) {\r
- return 0; // Prazno stablo je visine 0\r
- }\r
- return 1 + Math.max(brojNivoa(stablo.getLevi()), brojNivoa(stablo.getDesni()));\r
- }\r
-\r
- // Vraca najduzi string sadrzan kao vrednos u nekom od cvorova\r
- private static String najduzaVrednost(Stablo stablo) {\r
- if (stablo == null) {\r
- return null; // Prazno stablo ne sadrzi vrednosti\r
- }\r
- String rezultat = stablo.getVrednost();\r
- String levaVrednost = najduzaVrednost(stablo.getLevi());\r
- String desnaVrednost = najduzaVrednost(stablo.getDesni());\r
- if (rezultat == null || (levaVrednost != null && rezultat.length() < levaVrednost.length())) {\r
- rezultat = levaVrednost;\r
- }\r
- if (rezultat == null || (desnaVrednost != null && rezultat.length() < desnaVrednost.length())) {\r
- rezultat = desnaVrednost;\r
- }\r
- return rezultat;\r
- }\r
-\r
- // Ispisuje sve puteve od korena do listova\r
- private static void sviPutevi(Stablo stablo, List<String> put) {\r
- if (stablo == null) {\r
- return;\r
- }\r
- put.add(stablo.getVrednost());\r
- if ((stablo.getLevi() == null) && (stablo.getDesni() == null)) {\r
- Svetovid.out.println("Put: " + put);\r
- }\r
- sviPutevi(stablo.getLevi(), put);\r
- sviPutevi(stablo.getDesni(), put);\r
- put.remove(put.size() - 1);\r
- }\r
-\r
- // Vraca obrnuto stablo od datog\r
- private static Stablo obrni(Stablo stablo) {\r
- if (stablo == null) {\r
- return null;\r
- }\r
- Stablo levi = obrni(stablo.getLevi());\r
- Stablo desni = obrni(stablo.getDesni());\r
- Stablo obrnuto = new Stablo(stablo.getId(), stablo.getVrednost(), desni, levi);\r
- return obrnuto;\r
- }\r
-}\r
diff --git a/Stabla/Primeri za test/classic.txt b/Stabla/Primeri za test/classic.txt
+++ /dev/null
@@ -1,50 +0,0 @@
-49\r
-5 94 10 h\r
-94 136 97 a\r
-136 214 143 54\r
-214 219 -1 3g\r
-219 226 -1 ph\r
-226 -1 229 y4\r
-229 -1 230 515\r
-230 237 -1 mo0\r
-237 251 245 1adr\r
-251 -1 -1 a5f1\r
-245 -1 -1 2jl1\r
-143 -1 147 ak\r
-147 161 152 4a0\r
-161 182 165 14\r
-182 189 -1 50f5\r
-189 192 -1 2uh8\r
-192 193 -1 27r6\r
-193 194 -1 1ol4m\r
-194 209 201 2a3aq\r
-209 -1 -1 7aa8b\r
-201 -1 -1 2l3k6\r
-165 171 167 4ac3\r
-171 173 -1 1g7an\r
-173 -1 -1 8deri\r
-167 -1 -1 fe2n\r
-152 -1 -1 2p7\r
-97 106 -1 1m\r
-106 134 109 81\r
-134 -1 -1 1pu\r
-109 117 -1 1by\r
-117 129 123 iu0\r
-129 -1 -1 8tl8\r
-123 -1 -1 3bds\r
-10 67 18 9\r
-67 72 71 e6\r
-72 85 76 6n\r
-85 87 -1 km1\r
-87 -1 -1 2u0n\r
-76 -1 -1 1nm\r
-71 -1 -1 36\r
-18 29 26 1m\r
-29 58 32 67\r
-58 -1 -1 32\r
-32 51 41 mg\r
-51 -1 52 14y\r
-52 -1 -1 7uq\r
-41 44 -1 h1\r
-44 -1 -1 1ec\r
-26 -1 -1 19\r
diff --git a/Stabla/Primeri za test/indent.txt b/Stabla/Primeri za test/indent.txt
+++ /dev/null
@@ -1,99 +0,0 @@
-5 h\r
- 94 a\r
- 136 54\r
- 214 3g\r
- 219 ph\r
- 226 y4\r
- -\r
- 229 515\r
- -\r
- 230 mo0\r
- 237 1adr\r
- 251 a5f1\r
- -\r
- -\r
- 245 2jl1\r
- -\r
- -\r
- -\r
- -\r
- -\r
- 143 ak\r
- -\r
- 147 4a0\r
- 161 14\r
- 182 50f5\r
- 189 2uh8\r
- 192 27r6\r
- 193 1ol4m\r
- 194 2a3aq\r
- 209 7aa8b\r
- -\r
- -\r
- 201 2l3k6\r
- -\r
- -\r
- -\r
- -\r
- -\r
- -\r
- 165 4ac3\r
- 171 1g7an\r
- 173 8deri\r
- -\r
- -\r
- -\r
- 167 fe2n\r
- -\r
- -\r
- 152 2p7\r
- -\r
- -\r
- 97 1m\r
- 106 81\r
- 134 1pu\r
- -\r
- -\r
- 109 1by\r
- 117 iu0\r
- 129 8tl8\r
- -\r
- -\r
- 123 3bds\r
- -\r
- -\r
- -\r
- -\r
- 10 9\r
- 67 e6\r
- 72 6n\r
- 85 km1\r
- 87 2u0n\r
- -\r
- -\r
- -\r
- 76 1nm\r
- -\r
- -\r
- 71 36\r
- -\r
- -\r
- 18 1m\r
- 29 67\r
- 58 32\r
- -\r
- -\r
- 32 mg\r
- 51 14y\r
- -\r
- 52 7uq\r
- -\r
- -\r
- 41 h1\r
- 44 1ec\r
- -\r
- -\r
- -\r
- 26 19\r
- -\r
- -\r
diff --git a/Stabla/Primeri za test/pretty.txt b/Stabla/Primeri za test/pretty.txt
+++ /dev/null
@@ -1,49 +0,0 @@
- /-----(26) 19\r
- /-----(18) 1m\r
- | | /-----(41) h1\r
- | | | \-----(44) 1ec\r
- | | /-----(32) mg\r
- | | | | /-----(52) 7uq\r
- | | | \-----(51) 14y\r
- | \-----(29) 67\r
- | \-----(58) 32\r
- /-----(10) 9\r
- | | /-----(71) 36\r
- | \-----(67) e6\r
- | | /-----(76) 1nm\r
- | \-----(72) 6n\r
- | \-----(85) km1\r
- | \-----(87) 2u0n\r
--(5) h\r
- | /-----(97) 1m\r
- | | | /-----(109) 1by\r
- | | | | | /-----(123) 3bds\r
- | | | | \-----(117) iu0\r
- | | | | \-----(129) 8tl8\r
- | | \-----(106) 81\r
- | | \-----(134) 1pu\r
- \-----(94) a\r
- | /-----(152) 2p7\r
- | /-----(147) 4a0\r
- | | | /-----(167) fe2n\r
- | | | /-----(165) 4ac3\r
- | | | | \-----(171) 1g7an\r
- | | | | \-----(173) 8deri\r
- | | \-----(161) 14\r
- | | \-----(182) 50f5\r
- | | \-----(189) 2uh8\r
- | | \-----(192) 27r6\r
- | | \-----(193) 1ol4m\r
- | | | /-----(201) 2l3k6\r
- | | \-----(194) 2a3aq\r
- | | \-----(209) 7aa8b\r
- | /-----(143) ak\r
- \-----(136) 54\r
- \-----(214) 3g\r
- \-----(219) ph\r
- | /-----(230) mo0\r
- | | | /-----(245) 2jl1\r
- | | \-----(237) 1adr\r
- | | \-----(251) a5f1\r
- | /-----(229) 515\r
- \-----(226) y4\r