fork download
  1. #include <stdio.h>
  2.  
  3. //наивный алгоритм O(n^2)
  4. int* unique_del(int* f, int *l){
  5. int t, *p;
  6. for(; f != l; ++f){
  7. p = f + 1;
  8. while(p < l){
  9. if(*p == *f){
  10. t = *(l - 1);
  11. *(l - 1) = *p;
  12. *p = t;
  13. --p;
  14. --l;
  15. }
  16. ++p;
  17. }
  18. }
  19. return l;
  20. }
  21.  
  22.  
  23. int main(void){
  24. int* p, *e;
  25.  
  26. int A[] = { 1, 2, 2, 3, 1, 3, 4, 1, 3, 3, 5, 4, 6, 5 };
  27.  
  28. e = unique_del(A, A + sizeof(A)/sizeof(A[0]));
  29. for(p = &A[0]; p != e; ++p)
  30. printf("%d ", *p);
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 2052KB
stdin
Standard input is empty
stdout
1 2 4 3 5 6