[Pascal] Sort by merging- recursion

Last update on July 19, 2009 10:28 AM by jak58
Published by jak58
[Pascal] Sort by merging- recursion




Here is a recursive procedure which can sort an array of n integers using the method of sorting by merging :

Procedure Sort_Merge (Var t : TAB; g, d : integer);
Var
   m, i, j, k : integer;
   s : TAB;
Begin
     If d > g Then
     Begin         
          m := (g + d) Div 2;
          Sort_Merge (t, g, m);
          Sort_Merge (t, m + 1, d);
          
	    For i := m DownTo g Do
              s[i] := t[i];
          
	    For j := m + 1 To d Do
              s[d + m + 1 - j] := t[j];
          
	    i := g; j := d;
          For k := g To d Do
          Begin
               If s[i] < s[j] Then
               Begin
                    t[k] := s[i];
                    i := i + 1;
               End
               Else
                   Begin
                         t[k] := s[j];
                         j := j - 1;
                   End;
          End;
     End;
End;
Best answers for « Sort by merging recursion » in :
[Pascal language] Recursion within a Shell Sort Show [Pascal language] Recursion within a Shell Sort Recursion, in the computing or mathematical terms, is a method of defining functions in which the function being defined is applied within its own designation. The term is also used more...
[Pascal language] Recursion within a Bubble Sort Show [Pascal language] Recursion within a Bubble Sort Pascal is a stable, efficient and block-structured programming language. The "type" of variables used in Pascal language is made up of its semantic nature and its range of values, and can...
Partition Merge Show Partition Merge Merge two partitions with Windows Vista Merge two partitions with a particular software If you have a partitioned hard drive and you are running out of space on one of them, you can choose to merge it with another...
Sorting a table without using the sort function ShowSorting a table without using the sort function Getting started Pseudocode The coding Getting started First of all we initialize a variable $ max with the 1st value of table. Then we will make a loop until the table still contains...
[Pascal]TRI SHELL -Recursion Show[Pascal]TRI SHELL -Recursion Tri Shell Recursion Note: Tri Shell Recursion Below is a recursive process that allows sorting n integers using Tri Shell. Procedure Tri_Shell_Rec (Var t: TAB; n,h : integer); Var aux,i :...
Creating Shortcut key to merge cells ShowCreating Shortcut key to merge cells Issue Solution Note Issue If there a shortcut to be pressed on the keyboard to merge cells in excel? I was trying to find a code or any macro which will allow me to do this! Thanks for your...
Download PDF SaM (Split and Merge) ShowPDFsam is a tool to merge and cut PDF files. It is an open source application to treat PDF files. It requires Virtual Java machine 1.4.2 or superior version. With a simple and intuitive interface, you can: - split documents PDF into chapters, into...
Programming languages ShowProgramming language A "programming language" is a language designed to describe a set of consecutive actions to be executed by a computer. A programming language is therefore a practical way for us (humans) to give instructions to a...
WPAN (Wireless Personal Area Network) ShowWireless Personal Area Networks (WPAN) A wireless personal area network (WPAN for short) is a low-range wireless network which covers an area of only a few dozen metres. This sort of network is generally used for linking peripheral devices (like...
ASCII Code ShowData coding Morse code was the first code used for long-distance communication. Samuel F.B. Morse invented it in 1844. This code is made up of dots and dashes (a sort of binary code). It was used to carry out communication much faster than could...