SHARE
TWEET

Untitled

a guest Sep 19th, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   public boolean removeLastOccurrence(T data) {
  2.         if(size == 0)
  3.             throw new IllegalArgumentException("Cannot remove null data");
  4.  
  5.  
  6.         else if(tail.equals(data)) {
  7.             removeFromBack();
  8.             return true;
  9.         }
  10.         else if (size>2)
  11.         {
  12.             Node<T> temp = tail;
  13.             for(int i =1;i<size-1;i++) {
  14.                 //tail.getPrevious();
  15.                 if(tail.getData().equals(data)) {
  16.                     removeAtIndex(i);
  17.                     return true;
  18.                 }
  19.                 else {
  20.                     temp=temp.getPrevious();
  21.                 }
  22.             }
  23.         }
  24.         else if(head.getData().equals(data)) {
  25.             removeFromFront();
  26.             return true;
  27.         }
  28.         // Replace this line with your return statement
  29.         return false;
  30.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top