Advertisement
gur111

deduplicateCArray

Jun 30th, 2019
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5.  
  6. int *deduplicate_array(int *arr, int cells);
  7.  
  8. int main(void){
  9.     int *arr = malloc(sizeof(int)*10);
  10.     int i;
  11.     for(i = 0; i<10; i++){
  12.         arr[i] = 10;
  13.     }
  14.  
  15.     arr = deduplicate_array(arr, 10);
  16.     printf("now print:\n");
  17.  
  18.     for(i = 0; i<10; i++){
  19.         printf("%d\n", arr[i]);
  20.     }
  21.  
  22.     return 0;
  23.  
  24. }
  25.  
  26. int *deduplicate_array(int *arr, int cells){
  27.     int i,k, count, final_count = 0;
  28.  
  29.     for(i = 0; i<cells; i++){
  30.         for(count=0, k = i+1; k<cells; k++){
  31.  
  32.             if(arr[i] == arr[k]){
  33.                 count++;
  34.             }else{
  35.                 arr[k-count] = arr[k];
  36.             }
  37.         }
  38.         final_count += count;
  39.     }
  40.  
  41.     return (int *) realloc(arr, cells-final_count);
  42. }
  43.  
  44.  
  45.  
  46.  
  47. void reverse_bits(int x){
  48.     unsigned int mashuacher = 6752314;
  49.     unsigned int res = 0;
  50.     while(mashuacher){
  51.         res = mashuacher&1;
  52.         printf("%d", res);
  53.         mashuacher >>= 1;
  54.         res <<= 1;
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement