How to resolve the algorithm Compare a list of strings step by step in the ALGOL W programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Compare a list of strings step by step in the ALGOL W programming language

Table of Contents

Problem Statement

Given a   list   of arbitrarily many strings, show how to:

Each of those two tests should result in a single true or false value, which could be used as the condition of an   if   statement or similar. If the input list has less than two elements, the tests should always return true. There is no need to provide a complete program and output. Assume that the strings are already stored in an array/list/sequence/tuple variable (whatever is most idiomatic) with the name   strings,   and just show the expressions for performing those two tests on it (plus of course any includes and custom functions etc. that it needs),   with as little distractions as possible. Try to write your solution in a way that does not modify the original list,   but if it does then please add a note to make that clear to readers. If you need further guidance/clarification,   see #Perl and #Python for solutions that use implicit short-circuiting loops,   and #Raku for a solution that gets away with simply using a built-in language feature.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Compare a list of strings step by step in the ALGOL W programming language

Source code in the algol programming language

    % returns true if all elements of the string array a are equal, false otherwise %
    % As Algol W procedures cannot determine the bounds of an array, the bounds     %
    % must be specified in lo and hi                                                %
    logical procedure allStringsEqual ( string(256) array a ( * )
                                      ; integer     value lo, hi
                                      ) ;
    begin
        logical same;
        integer listPos;
        same    := true;
        listPos := lo + 1;
        while same and listPos <= hi do begin
            same    := a( lo ) = a( listPos );
            listPos := listPos + 1
        end;
        same
    end allStringsEqual ;

    % returns true if the elements of the string array a are in ascending order,    %
    % false otherwise                                                               %
    % As Algol W procedures cannot determine the bounds of an array, the bounds     %
    % must be specified in lo and hi                                                %
    logical procedure ascendingOrder  ( string(256) array a ( * )
                                      ; integer     value lo, hi
                                      ) ;
    begin
        logical ordered;
        integer listPos;
        ordered := true;
        listPos := lo + 1;
        while ordered and listPos <= hi do begin
            ordered := a( listPos - 1 ) < a( listPos );
            listPos := listPos + 1
        end;
        ordered
    end ascendingOrder ;

  

You may also check:How to resolve the algorithm Convex hull step by step in the ObjectIcon programming language
You may also check:How to resolve the algorithm Base64 decode data step by step in the JavaScript programming language
You may also check:How to resolve the algorithm Combinations step by step in the C# programming language
You may also check:How to resolve the algorithm Canny edge detector step by step in the D programming language
You may also check:How to resolve the algorithm Higher-order functions step by step in the Smalltalk programming language