Jump to content

Recommended Posts

Posted

Am o problema cu acest cod. E vorba despre parcurgerea in latime a unui graf neponderat. Graful se citeste dintr-un fisier text si este reprezentat tabelar. Introduc muchiile,varfurile,varful initial, am facut si citirea din fisier,doar ca la final nu imi afiseaza ordinea,ci doar "cozile" fara niciun numar.

Spoiler

#include<stdio.h>
#include<conio.h>
#include<malloc.h>


int a[20][20];
int viz[20],coada[20];//vectori
int pl,n,m,i,j,el,x,y,p,u,vf;

float * prelucrare_vector(char* nume,int* z)
{

FILE*f;
float* v,x;
v=NULL;

f=fopen(nume,"r");

if(f)
{
    (*z)=0;
    fscanf(f,"%f",&x);
    while(!feof(f)){
    (*z)++;
    fscanf(f,"%f",&x);
    }

    if(*z>0)
    {
    v=(float*)malloc((*z)*sizeof(float));
    rewind(f);

    (*z)=0;
    fscanf(f,"%f",&x);

    while(!feof(f)){
    
    v[*z]=x;
    (*z)++;
    fscanf(f,"%f",&x);
    }
    
    }
    fclose(f);
    
}
return v;
}

void main()
{
    float*b;
int t,i;

b=prelucrare_vector("g1.txt", &t);

if(!b) printf("Fisierul nu a fost deschis");
else{
    printf("Numarul de elemente : %d \n",t);
    for(i=0;i<t;i++)
        printf("%5.2f\t \n",*(b+i));

}


printf("Nr varfuri:");scanf("%d",&n);
    printf("Nr muchii:");scanf("%d",&m);
    for(i=1;i<=m;i++)
    {
        printf("x=");scanf("%d",&x);
        printf("y=");scanf("%d",&y);
        a[x][y]=1;
        a[y][x]=1;
        //x si y xtremetitati, varfuri sa zicem, de la 1-2 
    }

    for(i=1;i<=n;i++)
        viz=0;
    printf("Varf initial:");scanf("%d",&pl);
    viz[pl]=1;
    coada[1]=pl;
    u=1;//ultim
    p=1;//primul 

    while(p<=u)
    {
        el=coada[p];
        for(j=1;j<=n;j++)
            viz[j]=0;
            if((a[el][j]==1)&&(viz[j]==0));
        {
            u=u+1;
            coada=j;
            viz[j]=1;
        
        }
    p=p+1;
    
    } 


    for(i=1;i<=u;i++)
         
        printf("Coada[%d]=",i,coada);
    getch();  

}

 

Pe parcurgerea in adancime merge.

Ezel: If you f*ck my work, we f*ck your work without discussion.

 

 

 

  • 2 weeks later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.