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 Stringten İlk N Karakteri Kaldırma Örneği

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

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

Delphi Üç Kenarı Verilen Bir Üçgenin Alanını Bulma

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