title: Pcointing to the previous node of a linked list
body: <p>I have defined the node of a linked list like below:</p>
  
  <p>(The "next" part points to the next node and the "previous" part points to the previous node)</p>
  
  <pre><code>typedef struct node{
  char val;
  struct node* next;
  struct node* previous;
  }node_t;
  </code></pre>
  
  <p>And I have initialized three nodes like this:</p>
  
  <pre><code>node_t* head=NULL;
  head=malloc(sizeof(node_t));
  head-&gt;val='a';
  head-&gt;previous=NULL;
  head-&gt;next=malloc(sizeof(node_t));
  head-&gt;next-&gt;val='b';
  head-&gt;next-&gt;previous=head;
  head-&gt;next-&gt;next=malloc(sizeof(node_t));
  head-&gt;next-&gt;next-&gt;val='c';
  head-&gt;next-&gt;next-&gt;previous=head-&gt;next;
  head-&gt;next-&gt;next-&gt;next=NULL;
  node_t*current=head;
  </code></pre>
  
  <p>And my goal is that whenever the user type "R",then our current pointer will point to the next node and whenever the user type "L",then our current pointer will point to the previous node and whenever we type "P" then we can type a letter (char c) to add this letter as a new node before the current node.</p>
  
  <p>my code for this part is like this:</p>
  
  <pre><code>char input;
  scanf("%c",&amp;input);
  if(input=='R'){
         current=current-&gt;next;
     }
  if(input=='L'){
         current=current-&gt;previous;
     }
  if(input=='P'){
         char c;
         scanf(" %c",&amp;c);
         node_t * new=malloc(sizeof(node_t));
         new-&gt;val=c;
         new-&gt;next=current;
         new-&gt;previous=current-&gt;previous;
         current-&gt;previous-&gt;next=new;//need help to correct this part
     }
  </code></pre>
  
  <p>The "R" and "L" part works correctly but I don't know why the "P" part doesn't add the node.</p>
  
  <p>for example:</p>
  
  <p>input:</p>
  
  <p>R</p>
  
  <p>P j</p>
  
  <p>output:</p>
  
  <p>jbc</p>
  
  <p>but the output of this code is still bc.</p>