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 Dizideki Herhangi Bir Konuma Eleman Ekleme Örneği

Delphi 1'den N'e Kadar Asal Sayıları Bulma Örneği

Delphi While Döngüsü İle 10 Sayının Ortalamasını Bulma Örneği

Delphi Yarıçap Girilen Bir Dairenin Çevre ve Alanını Bulma Örneği