How to resolve the algorithm Compare a list of strings step by step in the ALGOL 68 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 68 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 68 programming language

Source code in the algol programming language

[]STRING list1 = ("AA","BB","CC");
[]STRING list2 = ("AA","AA","AA");
[]STRING list3 = ("AA","CC","BB");
[]STRING list4 = ("AA","ACB","BB","CC");
[]STRING list5 = ("single_element");

[][]STRING all lists to test = (list1, list2, list3, list4, list5);

PROC equal = ([]STRING list) BOOL:
   BEGIN
      BOOL ok := TRUE;
      FOR i TO UPB list - 1 WHILE ok DO
         ok := list[i] = list[i+1]
      OD;
      ok
   END;

PROC less than = ([]STRING list) BOOL:
   BEGIN
      BOOL ok := TRUE;
      FOR i TO UPB list - 1 WHILE ok DO
         ok := list[i] < list[i + 1]
      OD;
      ok
   END;

FOR i TO UPB all lists to test DO
   []STRING list = all lists to test[i];
   print (("list:", (STRING s; FOR i TO UPB list DO s +:= " " + list[i] OD; s), new line));
   IF equal (list) THEN
      print (("...is lexically equal", new line))
   ELSE
      print (("...is not lexically equal", new line))
   FI;
   IF less than (list) THEN
      print (("...is in strict ascending order", new line))
   ELSE
      print (("...is not in strict ascending order", new line))
   FI
OD

  

You may also check:How to resolve the algorithm Word wrap step by step in the Tailspin programming language
You may also check:How to resolve the algorithm Angle difference between two bearings step by step in the Jsish programming language
You may also check:How to resolve the algorithm Leap year step by step in the Nemerle programming language
You may also check:How to resolve the algorithm Cartesian product of two or more lists step by step in the Haskell programming language
You may also check:How to resolve the algorithm Find duplicate files step by step in the Wren programming language