Advertisement
Guest User

Triple_Action

a guest
Nov 21st, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1.  
  2. public class Triple_Actions
  3. {
  4.  
  5. // פעולה מספר 1
  6. //הפעולה מקבלת אורך של רשימה ויוצרת רשימה של שלשות(רשימה של triple)
  7. //ערכי Triple יהיו מספרים שלמים בטווח שבין 1 ל- 10 ויקבעו בצורה אקראית
  8. //הפעולה תחזיר מצביע לתחילת הרשימה שנוצרה
  9. // edgea = אורך צלע 1
  10. // edgeb = אורך צלע 2
  11. // edgeb = אורך צלע 3
  12. public static Node<Triple> createTripleList(int a)
  13. {
  14. //edgeA, edgeB, edge C
  15. int x=1;
  16. int y=10;
  17. int range = y-x +1;
  18. int num4;//(int)(Math.random()*range)+ x;
  19. int num5;// (int)(Math.random()*range)+ x;
  20. int num6;// (int)(Math.random()*range)+ x;
  21. int num1 = 2;// (int)(Math.random()*range)+ x;
  22. int num2 = 3;//(int)(Math.random()*range)+ x;
  23. int num3 = 5;//(int)(Math.random()*range)+ x;
  24. //Point p =new Point(X,Y);
  25. Triple t1 = new Triple(num1,num2,num3);
  26. //Node<Point> first =new Node<Point>(p);
  27. Node<Triple> first = new Node<Triple>(t1);
  28. Node<Triple>tmp =first;
  29. for(int i=1; i<a ; i++)
  30. {
  31.  
  32. num4 = (int)(Math.random()*range)+ x;
  33. num5 = (int)(Math.random()*range)+ x;
  34. num6 = (int)(Math.random()*range)+ x;
  35. // Point P =new Point(X,Y);
  36. Triple T1 =new Triple(num4,num5,num6);
  37. // Node<Point> S =new Node<Point>(P);
  38. Node<Triple> S =new Node<Triple>(T1);
  39. // tmp.setNext(S);
  40. // tmp = S;
  41. tmp.setNext(S);
  42. tmp = S;
  43. }
  44. return first;
  45.  
  46. }
  47. //פעולה מספר 2
  48. // הפעולה מקבלת : Triple
  49. //מחזירה : האם ניתן ניתן לבנות משולש ישר זווית מאורכי הצלעות
  50. //אם המשולש הוא משלוש ישר זווית אז צלעותיו הם :
  51. //a - ניצב
  52. //b - ניצב
  53. //c - ניצב
  54. //a^2 + b^2 = c^2
  55. public static boolean isRightTriangle(Node<Triple> first)
  56. {
  57. Node<Triple>tmp = first;
  58. //while(tmp != null)
  59. //{
  60. if(tmp.getValue().getEdgeC()> tmp.getValue().getEdgeA() && tmp.getValue().getEdgeC() > tmp.getValue().getEdgeB())
  61. {
  62. if(((tmp.getValue().getEdgeA())*(tmp.getValue().getEdgeA())) + ((tmp.getValue().getEdgeB())*(tmp.getValue().getEdgeB())) == ((tmp.getValue().getEdgeC())*(tmp.getValue().getEdgeC())))
  63. {
  64. return true;
  65. }
  66. }
  67. //}
  68. return false;
  69. }
  70.  
  71. //פעולה מספר 3
  72. //הפעולה מקבלת : רשימה של שלשות
  73. //הפעולה מורידה מהרשימה את כל השלשות שלא ניתן ליצור מהן משולש ישר זווית
  74. // הפעולה תחזיר מצביע לרשימה המעודכנת
  75. public static Node<Triple> removeIfNotRight(Node<Triple> first)
  76. {
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. Node<Triple>tmp=nextToNodeInIndex(first);
  88. // if (index==0) אפשר גם
  89. if (tmp == first)
  90. {
  91. return first.getNext();
  92. }
  93. else
  94. {
  95. tmp.setNext(tmp.getNext().getNext());
  96. return first;
  97. }
  98. }
  99.  
  100.  
  101.  
  102. //פעולה משנית ל-6
  103. //הפעולה המשנית מקבלת רשימה כללית ואינדקס
  104. // הפעולה תעבור על הרשימה עד לאיבר אחד לפני המקום של האינדקס(1-אינדקס)ק
  105. //הפעולה תחזיר את האיבר אחד לפני האיבר במקום של האינדקס
  106. public static Node<Triple> nextToNodeInIndex(Node<Triple> first)
  107. {
  108. for (int i = 0; i < (index-1); i++)
  109. {
  110. first = first.getNext();
  111. }
  112. return first;
  113. }
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133. // פעולה המדפיסה את הרשימה
  134. public static void print(Node node)
  135. {
  136. while(node !=null)
  137. {
  138. System.out.print(node);
  139. node = node.getNext();
  140. }
  141. }
  142.  
  143. public static void main(String[]args)
  144. {
  145. int a=10;
  146. print(createTripleList(a));
  147. System.out.println(isRightTriangle(createTripleList(a)));
  148. }
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement