Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Triple_Actions
- {
- // פעולה מספר 1
- //הפעולה מקבלת אורך של רשימה ויוצרת רשימה של שלשות(רשימה של triple)
- //ערכי Triple יהיו מספרים שלמים בטווח שבין 1 ל- 10 ויקבעו בצורה אקראית
- //הפעולה תחזיר מצביע לתחילת הרשימה שנוצרה
- // edgea = אורך צלע 1
- // edgeb = אורך צלע 2
- // edgeb = אורך צלע 3
- public static Node<Triple> createTripleList(int a)
- {
- //edgeA, edgeB, edge C
- int x=1;
- int y=10;
- int range = y-x +1;
- int num4;//(int)(Math.random()*range)+ x;
- int num5;// (int)(Math.random()*range)+ x;
- int num6;// (int)(Math.random()*range)+ x;
- int num1 = 2;// (int)(Math.random()*range)+ x;
- int num2 = 3;//(int)(Math.random()*range)+ x;
- int num3 = 5;//(int)(Math.random()*range)+ x;
- //Point p =new Point(X,Y);
- Triple t1 = new Triple(num1,num2,num3);
- //Node<Point> first =new Node<Point>(p);
- Node<Triple> first = new Node<Triple>(t1);
- Node<Triple>tmp =first;
- for(int i=1; i<a ; i++)
- {
- num4 = (int)(Math.random()*range)+ x;
- num5 = (int)(Math.random()*range)+ x;
- num6 = (int)(Math.random()*range)+ x;
- // Point P =new Point(X,Y);
- Triple T1 =new Triple(num4,num5,num6);
- // Node<Point> S =new Node<Point>(P);
- Node<Triple> S =new Node<Triple>(T1);
- // tmp.setNext(S);
- // tmp = S;
- tmp.setNext(S);
- tmp = S;
- }
- return first;
- }
- //פעולה מספר 2
- // הפעולה מקבלת : Triple
- //מחזירה : האם ניתן ניתן לבנות משולש ישר זווית מאורכי הצלעות
- //אם המשולש הוא משלוש ישר זווית אז צלעותיו הם :
- //a - ניצב
- //b - ניצב
- //c - ניצב
- //a^2 + b^2 = c^2
- public static boolean isRightTriangle(Node<Triple> first)
- {
- Node<Triple>tmp = first;
- //while(tmp != null)
- //{
- if(tmp.getValue().getEdgeC()> tmp.getValue().getEdgeA() && tmp.getValue().getEdgeC() > tmp.getValue().getEdgeB())
- {
- if(((tmp.getValue().getEdgeA())*(tmp.getValue().getEdgeA())) + ((tmp.getValue().getEdgeB())*(tmp.getValue().getEdgeB())) == ((tmp.getValue().getEdgeC())*(tmp.getValue().getEdgeC())))
- {
- return true;
- }
- }
- //}
- return false;
- }
- //פעולה מספר 3
- //הפעולה מקבלת : רשימה של שלשות
- //הפעולה מורידה מהרשימה את כל השלשות שלא ניתן ליצור מהן משולש ישר זווית
- // הפעולה תחזיר מצביע לרשימה המעודכנת
- public static Node<Triple> removeIfNotRight(Node<Triple> first)
- {
- Node<Triple>tmp=nextToNodeInIndex(first);
- // if (index==0) אפשר גם
- if (tmp == first)
- {
- return first.getNext();
- }
- else
- {
- tmp.setNext(tmp.getNext().getNext());
- return first;
- }
- }
- //פעולה משנית ל-6
- //הפעולה המשנית מקבלת רשימה כללית ואינדקס
- // הפעולה תעבור על הרשימה עד לאיבר אחד לפני המקום של האינדקס(1-אינדקס)ק
- //הפעולה תחזיר את האיבר אחד לפני האיבר במקום של האינדקס
- public static Node<Triple> nextToNodeInIndex(Node<Triple> first)
- {
- for (int i = 0; i < (index-1); i++)
- {
- first = first.getNext();
- }
- return first;
- }
- // פעולה המדפיסה את הרשימה
- public static void print(Node node)
- {
- while(node !=null)
- {
- System.out.print(node);
- node = node.getNext();
- }
- }
- public static void main(String[]args)
- {
- int a=10;
- print(createTripleList(a));
- System.out.println(isRightTriangle(createTripleList(a)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement