[Pascal language] Recursion within a Bubble Sort

Last update on May 28, 2009 12:41 PM by jak58
Published by netty5

[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 be expressed by a type name, an explicit value range, or as combination of both.


An interesting feature is that Pascal supports recursion, a computing tool allowing, a function or procedure within a program, to make calls to itself. Thus provide efficient coding solutions, by eliminating the use of tedious loops.

Here is a recursive procedure that allows a sort of (n) number of integers using the Bubble Sort method:


Bubble sort is a simple sorting algorithm. It works by constantly stepping through the list to be sorted, comparing two items at a time and swapping them if they are in the wrong order. (each number is compared to the number that follows it, swapping the two neighboring values into right order if necessary in the most inner loop).

Procedure Bubble_sort (var t : TAB; n : integer);
Var i, aux : integer;
    Function Sort (t : TAB; n : integer) : Boolean;
    Var ok : boolean; i : integer;
    Begin
         ok := true; i := 1;
         Repeat
               If t[i + 1] < t[i] Then ok := false
               Else i := i + 1;
         Until ((Not ok) or (i >= n));
         Sort := ok;
    End;
    Begin
         If Not Sort(t, n) Then
         Begin
              For i := 1 To n - 1 Do
                If t[i] > t[i + 1] Then
                   Begin
                        aux := t[i];
                        t[i] := t[i + 1];
                        t[i + 1] := aux;
                   End;
              Bubble_sort (t, n);
         End;
    End;
Best answers for « Recursion within a Bubble Sort » 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] Sort by merging- recursion Show [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 :...
Sorting a table without using the sort function Show Sorting 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...
Google - Search within the title or the URL ShowGoogle-Search within the title or the URL Search in the title Search in the URL Note Google allows you to query only the pages containing a term in their URL or in the page title. Search in the title Simply use the following...
[Excel] Sorting rows only Show[Excel] Sorting rows only Microsoft Excel by default perform a sort on the columns (Data/Sort). To sort the data horizontally, just select the data to be sorted, then Data tab /Sort/ Options/ check the Sort Left to right box in the...
[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 :...
Download Bubbloids ShowIt is not easy to get an original screen of wakefulness in spite of the choice which exists on the Web. Bubbloid is a screen of rather outstanding wakefulness to deserve your attention. To begin he has a collection of pictures there 3D which will...
Download Ridorium File Sorter ShowDescription The application is designed by Ridorium Corporation. File Sorter is a tool that allows you to sort your files within their category. It classifies all your files in good order and in any location on your computer. It enables you to save...
UNIX Commands ShowTable of the main UNIX commands Unix Commands Description Options ls lists the content of a directory -a Displays all files, including hidden files -I Displays a...
Linux - The shell ShowIntroduction to the shell The command interpreter is the interface between the user and the operating system, hence the name "shell". The shell therefore acts as an intermediary between the operating system and the user thanks to command lines...
MKV format (Matroska Video) ShowMKV format The MKV format (Matroska Video) is an entirely free video format. More precisely, it is a container (hence the name Matroska, in reference to the Russian dolls contained within another) making it possible to contain video (DivX, Xvid,...