Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileReader;
- import java.util.*;
- public class Main {
- public static void main(String[] args) throws Exception {
- Drzewo tree = new Drzewo();
- ArrayList<Elementy> lista = stworzListe();
- for (Elementy node: lista) {
- tree.insertBST(node);
- }
- // tree.wyswietl(tree._root);
- tree.wyswietl(tree._root);
- tree.queueBFS(tree._root);
- }
- public static String sameSlowa(String s) {
- String str = "";
- boolean kontrola = false;
- for (int i=0; i<s.length(); i++)
- if (Character.isLetter(s.charAt(i))) {
- kontrola = true;
- break;
- }
- if (kontrola) {
- for (int i = 0; i < s.length(); i++)
- if (Character.isLetter(s.charAt(i)))
- str += s.charAt(i);
- return str;
- }
- else return null;
- }
- public static ArrayList<Elementy> stworzListe () throws Exception {
- ArrayList<Elementy> elementy = new ArrayList<>();
- int wiersz = 1;
- Scanner sc = new Scanner(new FileReader("test.txt"));
- while (sc.hasNextLine()) {
- Scanner s2 = new Scanner(sc.nextLine());
- while (s2.hasNext()) {
- String s = s2.next();
- if(sameSlowa(s) != null) {
- String str = sameSlowa(s);
- Elementy node = new Elementy();
- node.data = str;
- if (elementy.contains(node)) {
- int ind = elementy.indexOf(node);
- Elementy n = elementy.get(ind);
- n.lista.add(wiersz);
- }
- else {
- node.lista.add(wiersz);
- elementy.add(node);
- }
- }
- }
- wiersz++;
- }
- return elementy;
- }
- public static void wypiszListe(ArrayList<Elementy> lista) {
- for(Elementy n: lista) {
- System.out.print(n.data +" ");
- for (Integer i: n.lista)
- System.out.print(i + ", ");
- System.out.print("\n");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement