title: counting redundancies in linked list in C
body: <p>I'm practicing code that can find redundancies in a linked list. 
  For example:</p>
  
  <p>INPUT</p>
  
  <blockquote>
    <p>777</p>
  </blockquote>
  
  <p>OUTPUT</p>
  
  <blockquote>
    <p>contains 2 redundancies</p>
  </blockquote>
  
  <p>INPUT</p>
  
  <blockquote>
    <p>32182</p>
  </blockquote>
  
  <p>OUTPUT</p>
  
  <blockquote>
    <p>contains 1 redundancies</p>
  </blockquote>
  
  <p>I'm struggling to actually track redundancies in my code. I'v sorted the linked list, then I assume I would just create 2 pointers one that traverses the current location of the linked list and one that traverses the previous location of the linked list and if they're equal count++. But I always get 0 redundancies.</p>
  
  <p>In the code below, I think my challenge is mainly in the countRedun() method.</p>
  
  <pre><code>
  struct digit * insertAtFront(struct digit *start, struct digit * newDig){
      struct digit * ptr = start;
      newDig = start;
      return newDig;
  
  }
  struct digit * insertIntoSorted(struct digit *start, struct digit *newDig) {
      struct digit *ptr = start;
      struct digit *prev = NULL;
      while ((ptr!=NULL) &amp;&amp; (ptr-&gt;num &lt; newDig-&gt;num)) {
          prev = ptr;
          ptr = ptr-&gt;next;
      }
      if (prev == NULL) {
          start = insertAtFront(start, newDig);
      } else {
          prev-&gt;next = newDig;
          newDig-&gt;next = ptr;
      }
      return(start);
  }
  
  struct digit * sortedCopy(struct digit * start) {
      //! heap1=showMemory(start=348, cursors=[start, ptr, sortedStart, newDigit])
      //! heap2=showMemory(start=519, cursors=[start, newDigit, ptr, prev])
      struct digit *ptr = start;
      struct digit *sortedStart = NULL;
      struct digit *newDigit;
  
      if (start!=NULL) {
          sortedStart = createDigit(start-&gt;num);
          ptr = ptr-&gt;next;
      }
      while (ptr!=NULL) {
          newDigit = createDigit(ptr-&gt;num);
          sortedStart = insertIntoSorted(sortedStart, newDigit);
          ptr = ptr-&gt;next;
      }
      return(sortedStart);
  }
  
  int countRedun(struct digit * start){
      struct digit  *sorted, *ptr, *prev, * curr;
      ptr = start;
      prev = start;
  
  
      //sort linked list
      sorted = sortedCopy(start);
      int count = 0;
  
      while(ptr != NULL)
      {
  
          if(ptr-&gt;num == prev-&gt;num)
          {
          count++;
          }
      prev = ptr;
      ptr = ptr-&gt;next;
      }
  
  }
  </code></pre>
  
  <p>I've excluded the code that asks user for input, as well as the linked list creator methods, assuming that the sorting, and counting methods are key for this question.</p>