Dizideki tekrarlanan elemanları silme

DrogbA

Forum Üyesi
Katılım
27 Ara 2020
Mesajlar
3,440
Tepkime puanı
0
Puanları
36
PHP:
 // Fonksiyon Kodları
public static Array DeleteDuplicates(Array arr)
{
   // this procedure works only with vectors
   if (arr.Rank != 1 )
      throw new ArgumentException("Multiple-dimension arrays are not supported");

   // we use a hashtable to track duplicates
   // make the hash table large enough to avoid memory re-allocations
   Hashtable ht = new Hashtable(arr.Length * 2);
   // we will store unique elements in this ArrayList
   ArrayList elements = new ArrayList();

   foreach (object Value in arr)
   {
      if ( !ht.Contains(Value) )
      {
         // we've found a non duplicate
         elements.Add(Value);
         // remember it for later
         ht.Add(Value, null);
      }
   }
   // return an array of same type as the original array
   return elements.ToArray(arr.GetType().GetElementType());
}

// Örnek Kullanım:
int[] numbers = new int[] {1, 3, 5, 2, 3, 1, 4};
int[] result = (int[]) DropDuplicates(numbers);
foreach (int num in result)
   Console.WriteLine(num);
 

Peri

Co Admin
Katılım
2 May 2020
Mesajlar
4,949
Tepkime puanı
0
Puanları
36
Takım
Beşiktaş
Teşekkürler
 

Nutella

Bayan Üye
Özel Üye
Katılım
2 Ocak 2021
Mesajlar
3,559
Tepkime puanı
0
Puanları
36
Cinsiyet
  1. Bayan
Takım
Galatasaray
Paylaşım için teşekkürler.
 
metal işleme
Üst