c - Lattices of Partial Order Set Segmentation Fault(core dumped) -


A set S = {x1, x2, x3, x4, x5, ....} whose size is n (& lt ; 20), I need a list of all the lattes (subsets of s) on the S with size (should be taken as input, but in my question I have fixed it for debugging purposes). The relation that has been defined in partial order is divisibility.

  #include & lt; Stdio.h & gt; # Include & lt; Stdbool.h & gt; Typedef Structure {int data; Structure node * next; } Node; Zero addEdge (node ​​* graph [], intestine one, int b) {node * ptr = (node ​​*) malloc (sizeof (node)); Ptr- & gt; Next = graph [a]; Ptr- & gt; Data = b; Graph [a] = ptr; } Zero BuildGraph (node ​​* graph [], int n) {int i, j; (I = 2; i & lt; = n; i ++) {for (j = 1; j & lt; = i / 2; j ++) {if (i% j == 0) {if (J! = 1) addEgege, I / J, I); And addEdge (graph, j, i); }}}} Zero print graph (node ​​* graph [], int n) {int i = 0; Node * ptr; For (i = 0; i & lt; = n; i ++) {ptr = graph [i]; Printf ("line-% d", i); While (ptr! = NULL) {printf ("% d", ptr-> Data); Ptr = ptr- & gt; Next; } Printf ("\ n"); }} Zero print (int array [], int n) {int i; For (i = 0; i & lt; n; i ++) printf ("% d", array [i]); Printf ("\ n"); } Bool check duplicate (int array [], int n, int a) {int i; For (i = 0; i & lt; n; i ++) if (array [i] == a) return false; Back true; } Zero form lattice (node ​​* graph [], int lattice [], int k, int vertex, int level) {// printf ("level-% d \ n", level); If (level> gt = k) returns; If (level == K) {lattice [level -1] = peak; Print (mesh, k); Return; } Lattice [level -1] = peak; Node * ptr = graph [top]; While (ptr! = Null) {// (check duplicate (lettuce, level, pt-> data)) form lattice (graph, lettuce, k, ptr-> data, level + 1); Ptr = ptr- & gt; Next; }} Void printLattice (node ​​* graph [], int n, int k) {int lattice [k], i; Node * ptr; {Ptr = graph [i] for (I = 1; i & lt; = n; i ++); While (ptr! = Null) {lettuce [= 0] =; FormLattice (graph, forged, k, ptr-> data, 2); Ptr = ptr- & gt; Next; }}} Int main (zero) {int n = 10, k = 4; Node * article [n + 1]; Int i; For (i = 0; i & lt; = n; i ++) graph [i] = null; BuildGraph (graph, n); // print graph (graph, n); // Hasse Diagram printLattice (graph, n, k) Comment to print; Return 0; }  

Showing the Segmentation Fault (Core Dump) Why is this happening? Thanks in advance

formLattice () The code is proof that only those text Are checked for lattice [level] which are related to lattice [level -1] . Of course, on every lattice, he does not have total order (i.e., not 1,2,3,6) How can the current program choose Top 3 for the lettuce [2] , while the top 2 is lettuce [1] ?

From let's to 0 to level-1 in all already Going for selected lessons, there should be another loop, around the current loop for ptr .


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -