title: Bubble sort in Prolog language
body: <p>I must implement the bubble sort function (the sorting algorithm).</p>
  
  <p>I have already implemented <code>bubblesort</code> and <code>swap</code>, a help function for <code>bubblesort</code>:</p>
  
  <pre><code>swap([X,Y|T1],[Y,X|T1]):-(Y&lt;X,!).
  swap([X|T1],[X|T2]):- swap(T1,T2).
  
  bubblesort([],[]) :- !.
  bubblesort(T1,T2) :- (bubblesort(swap(T1,T2),T2)).
  </code></pre>
  
  <p>I get an infinite loop. I must keep the signature of the function:</p>
  
  <blockquote>
    <p>bubblesort(T1,T2)</p>
  </blockquote>
  
  <p>I'm stuck on this question for 2 hours. Does anyone have an idea how I can do that?</p>