public
anonymous / gist:3793595
Created

  • Download Gist
gistfile1.c
C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
#include <stdio.h>
#include <stdlib.h>
 
typedef struct group group;
 
struct group {
int members;
int neighbours;
char color;
};
 
 
#define NUM_CELLS 10
 
void test_mgroup_arr(group clusters[][NUM_CELLS],group tests[NUM_CELLS], int num_groups, int is[NUM_CELLS], int js[NUM_CELLS]) {
 
int i;
int j = 0;
 
for (i = 0; i < num_groups; ++i)
clusters[i][j] = tests[i];
 
for (i = 0; i < NUM_CELLS; ++i) {
for (j=0; j < NUM_CELLS; ++j) {
clusters[i][j].members = i;
clusters[i][j].neighbours = j;
clusters[i][j].color = 'a';
}
}
 
for (i = 0; i < num_groups; ++i) {
clusters[is[i]][js[j]] = tests[i];
}
}
 
int main(void) {
 
group g1;
group g2;
 
g1.members = 1;
g1.neighbours = 2;
g1.color = 'b';
 
g2 = g1;
 
g1.members = 2;
 
printf("%d %d\n", g1.members, g1.neighbours);
printf("%d %d\n", g2.members, g2.neighbours);
 
group clusters[NUM_CELLS][NUM_CELLS];
 
int is[NUM_CELLS] = {1, 3, 5, 3, 4};
int js[NUM_CELLS] = {2, 3, 8, 1, 5};
 
int num_groups = 5;
 
group tests[NUM_CELLS];
tests[0].members = 101;
tests[0].neighbours = 111;
 
tests[1].members = 102;
tests[1].neighbours = 112;
 
tests[2].members = 103;
tests[2].neighbours = 113;
 
tests[3].members = 104;
tests[3].neighbours = 114;
 
tests[4] = tests[3];
 
test_mgroup_arr(clusters, tests, num_groups, is, js);
 
int i,j;
for (i = 0; i < NUM_CELLS; ++i) {
for (j=0; j < NUM_CELLS; ++j) {
printf("%d %d\n",clusters[i][j].members,clusters[i][j].neighbours);
}
}
 
return EXIT_SUCCESS;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.