title: Delete Even Number of Nodes in Linked List And Print in Reverse
body: <p>What should be the logic followed for this scenario.</p>
  
  <p>I have a linear linked list. I want to print the list in reverse order starting from the second last node.. but while removing even number of nodes. 
  For example: 
   34(Node 1- Odd), 65(Node 2 - even), 733(Node 3 - odd), 34(Node 4 - even),
  56(Node 5 - odd), 33(Node 6 - even)..</p>
  
  <p>Now, I want output like this..
  56 (Second last node), 733(Node 4 is removed being even and it is printed cz it is odd), 34(Again even removed, odd printed in reverse form) .. and so on.</p>
  
  <p>Please tell me if I have not cleared my question. And help me with the logic. 
  Thanks </p>
  
  <p><strong>Updated</strong></p>
  
  <pre><code>// Task A
  public class LinkedList {
  
      protected class NodeReference {
          int info;
          NodeReference next;
          public NodeReference pLoc;
      }
  
      NodeReference headRef,pLoc, Loc; 
      int totalElements;
      private NodeReference next; 
  
      public LinkedList() {
          totalElements = 0;
          headRef = null;
      }
  
      public void insertAtFront(int value) {
          NodeReference newNode = new NodeReference();
                  newNode.info = value;
                  newNode.next = headRef;
                  headRef = newNode;
      }
  // Task B
      public void printList(){
          NodeReference location = headRef;
          if(headRef!=null) {
               System.out.println("The list is being printed...."); 
               while(location != null) {
               System.out.println(location.info);
               location = location.next; 
               }
  
          } // if block ends
          else
              System.out.println("Sorry, List is Empty!");
      }   
  // Task C
      public NodeReference reverseList(NodeReference headRef) {
          if(headRef==null || headRef.next == null) 
              return headRef;
  
          NodeReference pLoc1 = headRef;
          NodeReference pLoc2 = headRef.next;
  
          headRef.next = null;
          while(pLoc1!= null || pLoc2!= null){
              NodeReference tempRef = pLoc2.next;
              pLoc2.next = pLoc1;
              pLoc1 = pLoc2;
              if (tempRef != null){
                  pLoc2 = tempRef;
              }else{
                  break;
              }
          }
  
          return pLoc2;
      }
      public void reverse() {
          reverseList(headRef);
      }
  // Task D 
      public void deleteEven() {
          Loc = headRef; pLoc = null;
          while (Loc != null) {
              Loc = (Loc.next).next;
              System.out.println(Loc.info); 
  
          }
      }
  }
  </code></pre>
  
  <p>Driver Program</p>
  
  <pre><code>public class LinkedListDriver {
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          LinkedList l = new LinkedList();
          l.insertAtFront(4); l.insertAtFront(7); 
          l.insertAtFront(3); l.insertAtFront(2);
          l.insertAtFront(8); l.insertAtFront(4);
          l.insertAtFront(6);
          l.printList(); 
          System.out.println("Printing Just Odd Values While Deleting Evens");
          try { 
              l.deleteEven();
          } catch(Exception e) {
              System.out.println(" End of the List..");
  
          }
  
  
  
      }
  
  }
  </code></pre>