Advertisement
Shailrshah

Removing Dublicates from an Array

Apr 19th, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include <stdio.h>
  2. void operation(int *array, int length)
  3. {
  4.     int count =0, i, *current , *end = array + length - 1;
  5.  
  6.     for ( current = array + 1; array < end; array++, current = array + 1 )
  7.     {
  8.         while ( current <= end )
  9.         {
  10.             if(*current == *array)
  11.                 *current = *end--;
  12.             else
  13.                 current++;
  14.         }
  15.         count++;
  16.     }
  17.     array -= count;
  18.     printf("The array without dublicates is \n");
  19.     while(array <= end)
  20.     {
  21.         printf("%d\t",*array);
  22.         array++;
  23.     }
  24. }
  25. int main()
  26. {
  27.     int a[100],b[100],l,i;
  28.     printf("Enter the array's limit: ");
  29.     scanf("%d",&l);
  30.     printf("Now enter %d elements.\n",l);
  31.     for(i=0; i<l; i++)
  32.         scanf("%d",&a[i]);
  33.     operation(a,l);
  34. }
  35. //Output
  36. //Enter the array's limit: 5
  37. //Now enter 5 elements.
  38. //1
  39. //2
  40. //1
  41. //2
  42. //8
  43. //The array without dublicates is
  44. //1       2       8
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement