How to resolve the algorithm Remove duplicate elements step by step in the Oberon-2 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Remove duplicate elements step by step in the Oberon-2 programming language

Table of Contents

Problem Statement

Given an Array, derive a sequence of elements in which all duplicates are removed. There are basically three approaches seen here:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Remove duplicate elements step by step in the Oberon-2 programming language

Source code in the oberon-2 programming language

MODULE RD;

IMPORT Out;
    
TYPE
  TArray = ARRAY 7 OF INTEGER;
  
VAR
  DataArray,ResultArray:TArray;
  ResultIndex,LastResultIndex,Position:LONGINT;
  IsNewNumber:BOOLEAN;

PROCEDURE Init(VAR A:TArray);
BEGIN
  A[0] := 1; A[1] := 2; A[2] := 2; A[3] := 3;
  A[4] := 4; A[5] := 5; A[6] := 5; 
END Init;

BEGIN
  Init(DataArray);
  ResultArray[0] := DataArray[0];
  LastResultIndex := 0;
  Position := 0;
  WHILE Position < LEN(DataArray)-1 DO
    INC(Position);
    IsNewNumber := TRUE;
    ResultIndex := 0;
    WHILE(ResultIndex <= LastResultIndex) & (IsNewNumber) DO
      IF DataArray[Position] = ResultArray[ResultIndex] THEN
	IsNewNumber := FALSE;
      END;
      INC(ResultIndex);
    END;
    IF IsNewNumber THEN
      INC(LastResultIndex);
      ResultArray[LastResultIndex] := DataArray[Position];
    END;
  END;
  FOR ResultIndex := 0 TO LastResultIndex DO
    Out.Int(ResultArray[ResultIndex],0); Out.Char(' ');
  END;
  Out.Ln;
END RD.

  

You may also check:How to resolve the algorithm Shell one-liner step by step in the Emacs Lisp programming language
You may also check:How to resolve the algorithm String length step by step in the Delphi programming language
You may also check:How to resolve the algorithm 100 doors step by step in the TorqueScript programming language
You may also check:How to resolve the algorithm Möbius function step by step in the D programming language
You may also check:How to resolve the algorithm Associative array/Iteration step by step in the Arturo programming language