Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package hr.fer.tel.ptm.examples;
- import hr.fer.tel.ptm.examples.datastructures.BinaryTree;
- import hr.fer.tel.ptm.examples.datastructures.Item;
- import hr.fer.tel.ptm.examples.datastructures.ItemContainer;
- import hr.fer.tel.ptm.examples.datastructures.QuaternaryTree;
- import hr.fer.tel.ptm.examples.datastructures.SinglyLinkedList;
- import hr.fer.tel.ptm.examples.datastructures.TernaryTree;
- import java.util.Random;
- /**
- *
- * @author saler
- */
- public class AllTests {
- public static void main(String[] args) {
- ItemContainer bt = new BinaryTree();
- ItemContainer tt = new TernaryTree();
- ItemContainer qt = new QuaternaryTree();
- ItemContainer sll = new SinglyLinkedList();
- //ukupni broj objekata
- final int N = 100;
- Item[] items = new Item[N];
- //dodat ćemo 0 kao prvi objekt (zbog balansiranja)
- items[0] = new Item(0);
- Random random = new Random();
- for (int i = 1; i < N; i++) {
- //dohvati objekt kao nasumični cijeli broj u intervalu [-N,N]
- Item item = new Item(new Integer(random.nextInt(2 * N + 1)) - N);
- //dodaj objekte u polje (služi za kasnije traženje)
- items[i] = item;
- }
- for (int i = 0; i < N; i++) {
- //dodaj objekte u binarno stablo
- bt = bt.add(items[i]);
- tt = tt.add(items[i]);
- qt = qt.add(items[i]);
- sll = sll.add(items[i]);
- System.out.println("Dodao sam " + items[i] + " u binarno stablo.");
- System.out.println("Dodao sam " + items[i] + " u ternarno stablo.");
- System.out.println("Dodao sam " + items[i] + " u kvaternarno stablo.");
- System.out.println("Dodao sam " + items[i] + " u singlylinkedlist.");
- }
- for (int i = 0; i < N; i++) {
- if (bt.contains(items[i])) {
- System.out.println("Pronašao sam " + items[i] + " u binarnom stablu.");
- }
- if (tt.contains(items[i])) {
- System.out.println("Dodao sam " + items[i] + " u ternarno stablo.");
- }
- if (qt.contains(items[i])) {
- System.out.println("Pronašao sam " + items[i] + " u kvaternarno stablu.");
- }
- if (sll.contains(items[i])) {
- System.out.println("Pronašao sam " + items[i] + " u singlylinkedlist.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment