Skip to content

Instantly share code, notes, and snippets.

Created September 27, 2012 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3793595 to your computer and use it in GitHub Desktop.
Save anonymous/3793595 to your computer and use it in GitHub Desktop.
#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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment