Guest User

Untitled

a guest
Jun 11th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package hr.fer.tel.ptm.examples;
  7.  
  8. import hr.fer.tel.ptm.examples.datastructures.BinaryTree;
  9. import hr.fer.tel.ptm.examples.datastructures.Item;
  10. import hr.fer.tel.ptm.examples.datastructures.ItemContainer;
  11. import hr.fer.tel.ptm.examples.datastructures.QuaternaryTree;
  12. import hr.fer.tel.ptm.examples.datastructures.SinglyLinkedList;
  13. import hr.fer.tel.ptm.examples.datastructures.TernaryTree;
  14. import java.util.Random;
  15.  
  16. /**
  17. *
  18. * @author saler
  19. */
  20. public class AllTests {
  21.  
  22. public static void main(String[] args) {
  23.  
  24. ItemContainer bt = new BinaryTree();
  25. ItemContainer tt = new TernaryTree();
  26. ItemContainer qt = new QuaternaryTree();
  27. ItemContainer sll = new SinglyLinkedList();
  28.  
  29. //ukupni broj objekata
  30. final int N = 100;
  31. Item[] items = new Item[N];
  32.  
  33. //dodat ćemo 0 kao prvi objekt (zbog balansiranja)
  34. items[0] = new Item(0);
  35.  
  36. Random random = new Random();
  37. for (int i = 1; i < N; i++) {
  38. //dohvati objekt kao nasumični cijeli broj u intervalu [-N,N]
  39. Item item = new Item(new Integer(random.nextInt(2 * N + 1)) - N);
  40. //dodaj objekte u polje (služi za kasnije traženje)
  41. items[i] = item;
  42. }
  43.  
  44. for (int i = 0; i < N; i++) {
  45. //dodaj objekte u binarno stablo
  46. bt = bt.add(items[i]);
  47. tt = tt.add(items[i]);
  48. qt = qt.add(items[i]);
  49. sll = sll.add(items[i]);
  50. System.out.println("Dodao sam " + items[i] + " u binarno stablo.");
  51. System.out.println("Dodao sam " + items[i] + " u ternarno stablo.");
  52. System.out.println("Dodao sam " + items[i] + " u kvaternarno stablo.");
  53. System.out.println("Dodao sam " + items[i] + " u singlylinkedlist.");
  54. }
  55.  
  56. for (int i = 0; i < N; i++) {
  57. if (bt.contains(items[i])) {
  58. System.out.println("Pronašao sam " + items[i] + " u binarnom stablu.");
  59. }
  60. if (tt.contains(items[i])) {
  61. System.out.println("Dodao sam " + items[i] + " u ternarno stablo.");
  62. }
  63. if (qt.contains(items[i])) {
  64. System.out.println("Pronašao sam " + items[i] + " u kvaternarno stablu.");
  65. }
  66. if (sll.contains(items[i])) {
  67. System.out.println("Pronašao sam " + items[i] + " u singlylinkedlist.");
  68. }
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment