Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- int check_elem(int elem, int *v, int dim){
- // return 1 iff elem in v; 0 altrimenti
- for(int i = 0; i!=dim; i++){
- if(v[i] == elem){
- return 1;
- }
- }
- return 0;
- }
- int *noRipetizioni(int **A, int nr, int nc){
- int dim = nr*nc;
- int *V = malloc(sizeof(*v) * dim);
- size_t num_elem = 0;
- if(!V){
- return NULL;
- }
- // inizializzo il vettore
- for(int i = 0; i!=dim; i++){
- V[i] = 0;
- }
- for(int j = 0; j!=nc; j++){
- for(int i = 0; i!=nr; i++){
- if( num_elem && !check_elem(A[i][j], V, dim) ){
- V[i] = A[i][j];
- num_elem++;
- }
- }
- }
- if(dim != num_elem){
- V = realloc(V, sizeof(*V) * num_elem);
- }
- if(!V){
- return NULL;
- }
- return V;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement