Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class listsSHIT
- {
- public static boolean isTriangle(Node<Integer> L)
- {
- return (L != null && count(L) % 3 == 0 && isEveryThirdEqual(L));
- }
- public static int count(Node<Integer> L)
- {
- Node<Integer> save = L;
- int counter = 0;
- while(save.hasNext())
- {
- counter++;
- save = save.getNext();
- }
- return counter;
- }
- public static boolean isEveryThirdEqual(Node<Integer> L)
- {
- int counter = count(L);
- Node<Integer> save = L;
- Node<Integer> first = new Node<Integer>(save.getValue());
- Node<Integer> first1 = first;
- for(int i = 0; i < counter / 3; i++)
- {
- first1.setNext(new Node<Integer>(save.getNext().getValue()));
- first1 = first1.getNext();
- save = save.getNext();
- }
- Node<Integer> second = new Node<Integer>(save.getValue());
- Node<Integer> second1 = second;
- for(int i = 0; i < counter / 3; i++)
- {
- second1.setNext(new Node<Integer>(save.getNext().getValue()));
- second1 = second1.getNext();
- save = save.getNext();
- }
- Node<Integer> third = new Node<Integer>(save.getValue());
- Node<Integer> third1 = second;
- for(int i = 0; i < counter / 3; i++)
- {
- third1.setNext(new Node<Integer>(save.getNext().getValue()));
- third1 = third1.getNext();
- save = save.getNext();
- }
- int checker = 0;
- for(int i = 0; i < counter / 3; i++)
- {
- if(first.getValue() == second.getValue() && second.getValue() == third.getValue())
- {
- checker++;
- }
- }
- if(checker == counter / 3)
- return true;
- else
- return false;
- }
- public static void main(String[] args)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement