title: Shifting Vowels at the end of the Singly Linklist
body: <p>The following is the code I have written to solve the particular problem. But I am having problems with solving two edge cases. The case where the first element itself is a vowel, and the case where the last element is the vowel. Now as for the first edge case, I think it can be solved by iterating through the list till we find a vowel, and inserting the head node before the said node, and update the head pointer. But in the 2nd case, the case where the last element is a vowel, in that case, my code is running into an infinite loop. How can I handle that particular case? Also, if you can suggest any different approach towards solving the problem, please do so and if you can, please suggest any kind of improvement I can apply in the code.</p>
  
  <pre><code>#include&lt;iostream&gt;
  
  using namespace std;
  
  struct node
  {
      char ch;
      node *next;
  };
  
  void enqueue (node **head, node **tail, char val)
  {
      node *newn = (node *)malloc(sizeof(node));
      newn-&gt;ch = val;
      newn-&gt;next = NULL;
  
      if (*head == NULL)
      {
          *head = newn;
          *tail = newn;
      }
  
      (*tail)-&gt;next = newn;
      (*tail) = newn;
  
  }
  
  void print (node *head)
  {
      while (head!=NULL)
      {
          cout&lt;&lt;head-&gt;ch&lt;&lt;" ";
          head = head-&gt;next;
      }
      cout&lt;&lt;endl;
  }
  
  bool isVowel (char ch)
  {
      ch = ch | 32;
  
      if (ch == 'a' || ch =='e' || ch=='i' || ch=='o' || ch=='u')
          return true;
      return false;
  
  }
  
  
  
  node* segregateVowels (node *head, node *tail)
  {
      if (head == NULL)
          return head;
  
      node *temp = head;
      node *fin = tail;
  
      while (temp!=fin)
      {
          cout&lt;&lt;temp-&gt;ch&lt;&lt;" "&lt;&lt;fin-&gt;ch&lt;&lt;endl;
          getchar();
          if (isVowel(temp-&gt;next-&gt;ch))
          {
              node *shift = temp-&gt;next;
              temp-&gt;next = temp-&gt;next-&gt;next;
              tail-&gt;next = shift;
              shift-&gt;next = NULL;
              tail = shift;
          }
          else
              temp = temp-&gt;next;
  
      }
      return head;
  
  }
  
  
  int main()
  {
      srand(time(NULL));
  
      node *head = NULL, *tail = NULL;
  
      int i = 20;
  
      while (i&gt;=0)
      {
          enqueue (&amp;head, &amp;tail, rand()%26+65);
          i--;
      }
  
      print(head);
  
  
      head = segregateVowels (head, tail);
  
  
      print(head);
  }
  </code></pre>