Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <assert.h>
- typedef struct grafo
- {
- char *vett;
- int *mat;
- }grafo;
- typedef grafo *pgrafo;
- void genera_vettore(pgrafo *k,int n)
- {
- (*k)->vett=calloc(n,sizeof(char));
- int i;
- for(i=0;i<n;i++)
- {
- printf("Inserire il %d elemento: ",i+1);
- fflush(stdin);
- scanf("%c",&(*k)->vett[i]);
- }
- }
- void genera_grafo(pgrafo *k,int n)
- {
- (*k)->mat=calloc(n*n,sizeof(int));
- int i,j;
- for(i=0;i<n;i++)
- {
- for(j=0;j<n;j++)
- {
- printf("Il nodo %c \x82 collegato a %c ? [Inserire 1 se si | 0 se no ]",(*k)->vett[i],(*k)->vett[j]);
- scanf("%d",&(*k)->mat[i*n+j]);
- }
- }
- }
- void stampa (pgrafo k,int n)
- {
- int i,j;
- for(i=0;i<n;i++)
- {
- printf("\n %c",k->vett[i]);
- for(j=0;j<n;j++)
- {
- if(k->mat[i*n+j]>0)
- printf("->%c",k->vett[j]);
- }
- }
- printf("->NULL");
- }
- int main()
- {
- pgrafo k;
- int n;
- printf("Inserire il numero di nodi: ");
- scanf("%d",&n);
- k=calloc(1,sizeof(grafo));
- genera_vettore(&k,n);
- genera_grafo(&k,n);
- stampa(k,n);
- }
Advertisement
Add Comment
Please, Sign In to add comment