Advertisement
Yuvalxp8

Lists Nodes

Oct 28th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.93 KB | None | 0 0
  1. public class listsSHIT
  2. {
  3.    
  4.     public static boolean isTriangle(Node<Integer> L)
  5.     {
  6.         return (L != null && count(L) % 3 == 0 && isEveryThirdEqual(L));
  7.     }
  8.  
  9.     public static int count(Node<Integer> L)
  10.     {
  11.         Node<Integer> save = L;
  12.         int counter = 0;
  13.         while(save.hasNext())
  14.         {
  15.             counter++;
  16.             save = save.getNext();
  17.         }
  18.         return counter;
  19.     }
  20.  
  21.     public static boolean isEveryThirdEqual(Node<Integer> L)
  22.     {
  23.         int counter = count(L);
  24.         Node<Integer> save = L;
  25.         Node<Integer> first = new Node<Integer>(save.getValue());
  26.         Node<Integer> first1 = first;
  27.         for(int i = 0; i < counter / 3; i++)
  28.         {
  29.             first1.setNext(new Node<Integer>(save.getNext().getValue()));
  30.             first1 = first1.getNext();
  31.             save = save.getNext();
  32.         }
  33.  
  34.         Node<Integer> second = new Node<Integer>(save.getValue());
  35.         Node<Integer> second1 = second;
  36.         for(int i = 0; i < counter / 3; i++)
  37.         {
  38.             second1.setNext(new Node<Integer>(save.getNext().getValue()));
  39.             second1 = second1.getNext();
  40.             save = save.getNext();
  41.         }
  42.  
  43.         Node<Integer> third = new Node<Integer>(save.getValue());
  44.         Node<Integer> third1 = second;
  45.         for(int i = 0; i < counter / 3; i++)
  46.         {
  47.             third1.setNext(new Node<Integer>(save.getNext().getValue()));
  48.             third1 = third1.getNext();
  49.             save = save.getNext();
  50.         }
  51.  
  52.         int checker = 0;
  53.  
  54.         for(int i = 0; i < counter / 3; i++)
  55.         {
  56.             if(first.getValue() == second.getValue() && second.getValue() == third.getValue())
  57.             {
  58.                 checker++;
  59.             }
  60.         }
  61.         if(checker == counter / 3)
  62.             return true;
  63.         else
  64.             return false;
  65.  
  66.     }
  67.  
  68.  
  69.     public static void main(String[] args)
  70.     {
  71.        
  72.     }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement