Advertisement
Huskymeister

Pesky Doubles

Feb 18th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. public static void ridOfDoubles(ref int[] arr)
  2.         {
  3.  
  4.             int count = 0;
  5.  
  6.             for (int i = 0; i < arr.Length; i++)
  7.             {
  8.                 for (int j = 1; j < arr.Length; i++)
  9.                 {
  10.                     if (arr[i] == arr[j])
  11.                     {
  12.                         arr[j] = -1; // Marks for deletion
  13.                         count++;
  14.                     }
  15.                 }
  16.             }
  17.  
  18.             for (int i = 0; i < arr.Length; i++)
  19.             {
  20.                 if (arr[i] == -1)
  21.                 {
  22.                     for (int j = i + 1; j < arr.Length; i++)
  23.                     {
  24.                         arr[j - 1] = arr[j];
  25.                     }
  26.                 }
  27.             }
  28.  
  29.             Array.Resize(ref arr, arr.Length - count);
  30.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement