Delphi Bir Listede Birden Çok Olan Elemanları Göstermek

"Delphi" Programlama dilinde "Bir Listede Birden Çok Olan Elemanları Göstermek" ile ilgili örnek kod aşağıda verilmiştir.

program FindDuplicates;

{$APPTYPE CONSOLE}

uses
  SysUtils, Classes, Generics.Collections;

var
  SampleList: TList;
  Duplicates: TList;
  CountMap: TDictionary;
  I: Integer;
begin
  SampleList := TList.Create;
  SampleList.AddRange([10, 20, 60, 30, 20, 40, 30, 60, 70, 80]);

  Duplicates := TList.Create;
  CountMap := TDictionary.Create;
  try
    for I := 0 to SampleList.Count - 1 do
    begin
      if CountMap.ContainsKey(SampleList[I]) then
        CountMap[SampleList[I]] := CountMap[SampleList[I]] + 1
      else
        CountMap.Add(SampleList[I], 1);
    end;

    for I in CountMap.Keys do
    begin
      if CountMap[I] > 1 then
        Duplicates.Add(I);
    end;

    Writeln(Duplicates.ToArray);
  finally
    SampleList.Free;
    Duplicates.Free;
    CountMap.Free;
  end;
end.



İlginizi Çekebilir

Delphi Bir Sayının Tek Mi Çift Mi Olduğunu Göstermek

Delphi Bir Dizi Gerçek Sayının Çarpımını Bulma Örneği

Delphi Bir Sayının Asal Sayı Olup Olmadığını Bulma Örneği

Delphi 1'den 100'e Kadar Sayı Toplam Örneği

Delphi Bir Dizideki Tek Sayıların Adetini Bulma Örneği