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
|
#include <stdlib.h>
#include <stdio.h>
struct graph
{
int nbArcs;
long *allAdjOut;
};
void *f (struct graph *orientedGraph, struct graph *notOriented)
{
int i;
for (i = 0; i < orientedGraph->nbArcs * 2; ++i)
printf ("%ld ", notOriented->allAdjOut[i]);
printf ("\n");
if ((notOriented->allAdjOut =
realloc (notOriented->allAdjOut, notOriented->nbArcs)) == NULL)
{
perror ("realloc");
return NULL;
}
for (i = 0; i < notOriented->nbArcs; ++i)
printf ("%ld ", notOriented->allAdjOut[i]);
printf ("\n");
return NULL;
}
void add (struct graph *this, long data)
{
long *p = realloc (this->allAdjOut, this->nbArcs + 1);
if (p != NULL)
{
this->allAdjOut = p;
this->allAdjOut[this->nbArcs] = data;
this->nbArcs++;
}
}
int main (void)
{
struct graph orientedGraph = { 0 };
struct graph notOriented = { 0 };
add (&orientedGraph, 1);
add (&orientedGraph, 2);
add (&orientedGraph, 3);
add (&orientedGraph, 4);
add (¬Oriented, 5);
add (¬Oriented, 6);
f (&orientedGraph, ¬Oriented);
return 0;
} |
Partager