title: How can I use this merge sort code in Prolog?
body: <p>So I have this merge sort code</p>
  <pre><code>merge(List, List, []).
  merge(List, [], List).
  
  merge([MinList1|RestMerged], [MinList1|RestList1], [MinList2|RestList2]) :-
    MinList1 =&lt; MinList2,
    merge(RestMerged,RestList1,[MinList2|RestList2]).
  merge([MinList2|RestMerged], [MinList1|RestList1], [MinList2|RestList2]) :-
    MinList2 =&lt; MinList1,
    merge(RestMerged,[MinList1|RestList1],RestList2).
  
  mergeSort([], []).
  mergeSort([A], [A|[]]).
  
  mergeSort(Sorted, List) :-
      length(List, N),
      FirstLength is //(N, 2),
      SecondLength is N - FirstLength,
      length(FirstUnsorted, FirstLength),
      length(SecondUnsorted, SecondLength),
      append(FirstUnsorted, SecondUnsorted, List),
      mergeSort(FirstSorted, FirstUnsorted),
      mergeSort(SecondSorted, SecondUnsorted),
      merge(Sorted, FirstSorted, SecondSorted).
  </code></pre>
  <p>but instead of doing</p>
  <p><strong>mergeSort(S, [9,8,7,6,5]).</strong></p>
  <p>on prolog, how can I use it by asking the user how many numbers to input and then proceed to input numbers that will be sorted.</p>
  <p>For example:</p>
  <p>Number of items? <strong>5</strong>
  <em>here the user will input 5 numbers to be sorted</em>
  <strong>9.</strong>
  <strong>8.</strong>
  <strong>7.</strong>
  <strong>6.</strong>
  <strong>5.</strong></p>
  <p>and the final answer will be</p>
  <p><strong>S=[5,6,7,8,9].</strong></p>