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 Faktöriyelini Bulma Örneği

Delphi Bir Stringteki Küçük Harfleri Öne Alma Örneği

Delphi Dizideki Herhangi Bir Konuma Eleman Ekleme Örneği

Delphi Santigrat Cinsinden Sıcaklığı Fahrenheit'e Çevirmek

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