title: Implementing a sorting method similar to bubble sort
body: <p>I am trying to figure out how to implement a sorting method that is like bubble sort but differs in some ways.</p>
  
  <p>The pseudo code would be like this:</p>
  
  <ol>
  <li>Get list and take first element in the list</li>
  <li>if the element next to it is smaller then swap the elements </li>
  <li>else mark the element as moved and repeat until all elements are marked</li>
  </ol>
  
  <p>Here is how I thought about implementing this problem:</p>
  
  <pre><code>sortElement [] elm= []
  sortElement [x] elm= [x]
  sortElement lis@(x:y:xs) elm = 
  --first if is to find the element in the list that i want to move
  if elm /=x  
  then x:sortElement(y:xs) elm 
  else if x &gt; y then y:sortElement(x:xs) elm 
  else lis
  
  stackBubble lis = stackBubble' lis lis
  
  stackBubble' [] [] = [] 
  stackBubble' [x] [] = [x]
  stackBubble' [] [x] = []
  stackBubble' lis@(x:xs) lis1@(x1:xs1) = do 
  
  sortElement(stackBubble' lis xs1) x1
  </code></pre>
  
  <p>The error I am getting is</p>
  
  <blockquote>
    <p>Non-exhaustive patterns in function stackBubble'</p>
  </blockquote>
  
  <p>If I do like suggested elsewhere: </p>
  
  <pre><code>sortElement(x:stackBubble' xs xs1) x1
  </code></pre>
  
  <p>I get a fully sorted list after one iteration when I would like to get something like this:</p>
  
  <pre><code>[4,2,7,1] =&gt; iterating 4 [2,4,7,1], after iterating all the elements [2,4,1,7].
  </code></pre>