title: Keeping track of the position of 'the cursor' in a doubly linked list (Java)
body: <p>I have implemented a DLL for adding and deleting characters. The purpose of the code is to give the output for registered keypresses. An example is that 'bai-d' will give 'bad' (the '-' represents the backspace).
  So far these adding and deleting operations are going fine. But the registered keypresses also contain '&lt;' and '>', which represent the shift of the cursor to the left and the right. An example is 'ball&lt; &lt; d > >--' which has to give 'bad'.
  I find it hard to come up with a method to include the '&lt;' and '>' in my code.</p>
  
  <pre><code>            MyLinkedList newList = new MyLinkedList();
              String password = input.nextLine();
  
              for (char ch : password.toCharArray()){
                  if(Character.isLetter(ch) || Character.isDigit(ch)){
                      newList.addRear(ch);
                      }
  
                  if(ch == '-'){
                      newList.removeRear();                       
                  }
                  /*if(ch == '&lt;'){
                      //cursor shifting
  
                  }
                  if(ch == '&gt;'){
                      //cursor shifting
                  }*/
          }   
  
              newList.print();
  
  }
  </code></pre>
  
  <p>Here I just call the methods for the characters. In the following section I will put a part of my implementation of the DLL. I have methods for the size, inserting at the front and back, deleting from the front and back.</p>
  
  <pre><code>public void removeFront(){ 
      if(head==null) return;
  
      head = head.next;
      head.previous = null;
      size--;
  }
  
  public void removeRear(){ 
      if(head==null) return;
      if(head.next == null){
          head = null;
          size--;
          return; 
      }
      Link current = head;
      while(current.next.next != null){
          current = current.next;
      }
      current.next = null;
      size--;
  }
  public void addFront(char data){ 
      if(head==null){
          head = new Link(null, data, null);
          }
  
      else{
          if(Character.isLetter(data) || Character.isDigit(data)){
              Link newLink = new Link(null, data, head); 
              head.previous = newLink; 
              head = newLink; 
          }
      }
      size++;
  }
  
  public void addRear(char data){ 
      if (head==null){
          head= new Link(null, data, null);   
      }
      else{
          Link current = head;
          while(current.next != null){
              current = current.next;
          }
          Link newLink = new Link(current, data, null);
          current.next = newLink;
      }
      size++;
  }
  </code></pre>
  
  <p>I would appreciate your help and suggestions!</p>