Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <time.h>
- #define MALLOCATE(p,size) { p = malloc(size); if(!p) {printf("Nedovoljno memorije"); exit(1); }}
- #define CALLOCATE(p,n,size) { p = calloc(n,size); if(!p) {printf("Nedovoljno memorije"); exit(1); }}
- #define REALLOCATE(p,size) { p = realloc(p,size); if(!p) {printf("Nedovoljno memorije"); exit(1); }}
- typedef struct{
- int number;
- int enabled;
- int lf,rf,df,uf;
- }Polje;
- typedef struct{
- int x,y;
- }Lavirint;
- int datyt = 1;
- int graf = 0;
- void ispis(Polje **a,int n, int m,int ulazx,int ulazy,int izlazx[],int izlazy[], int nz){
- //printf("uso");
- if(datyt)
- {
- //printf("uso1");
- int i,j;
- char **c;
- //c = malloc((2*n+1)*sizeof(*c));
- MALLOCATE(c,(2*n+1)*sizeof(*c))
- for(i=0;i<(2*n+1);i++)
- //c[i] = malloc((2*m+1)*sizeof(*c[i]));
- MALLOCATE(c[i],(2*m+1)*sizeof(*c[i]))
- //printf("usoOOOOOOO");
- for(i=0;i<(2*n+1);i++)
- for(j=0;j<(2*m+1);j++)
- c[i][j] = '*';
- for(i=0;i<n;i++){
- for(j=0;j<m;j++){
- //printf("usao");
- //printf("PIH1");
- if(a[i][j].enabled){
- //printf("usao2");
- //printf("PIH2");
- if(i==ulazx && j==ulazy)
- c[2*i+1][2*j+1] = 'O';
- else c[2*i+1][2*j+1] = ' ';
- int ii;
- for(ii=0;ii<nz;ii++)
- if(izlazx[ii] == i && izlazy[ii] == j)
- c[2*i+1][2*j+1] = 'X';
- if(a[i][j].lf) c[2*i+1][2*j] = ' ';
- if(a[i][j].rf) c[2*i+1][2*j+2] = ' ';
- if(a[i][j].df) c[2*i+2][2*j+1] = ' ';
- if(a[i][j].uf) c[2*i][2*j+1] = ' ';
- }
- }
- }
- for(i=0;i<(2*n+1);i++){
- for(j=0;j<(2*m+1);j++){
- printf("%c ",c[i][j]);
- }
- free(c[i]);
- printf("\n");
- }
- free(c);
- putchar('\n');
- }else {
- //printf("uso2");
- FILE *f = fopen("rezultati.txt","w");
- int i,j;
- char **c;
- //printf("uso3");
- //c = malloc((2*n+1)*sizeof(*c));
- MALLOCATE(c,(2*n+1)*sizeof(*c))
- for(i=0;i<(2*n+1);i++)
- //c[i] = malloc((2*m+1)*sizeof(*c[i]));
- MALLOCATE(c[i],(2*m+1)*sizeof(*c[i]))
- for(i=0;i<(2*n+1);i++)
- for(j=0;j<(2*m+1);j++)
- c[i][j] = '*';
- for(i=0;i<n;i++){
- for(j=0;j<m;j++){
- //printf("usao");
- if(a[i][j].enabled){
- //printf("usao2");
- if(i==ulazx && j==ulazy)
- c[2*i+1][2*j+1] = 'O';
- else c[2*i+1][2*j+1] = ' ';
- int ii;
- for(ii=0;ii<nz;ii++)
- if(izlazx[ii] == i && izlazy[ii] == j)
- c[2*i+1][2*j+1] = 'X';
- if(a[i][j].lf) c[2*i+1][2*j] = ' ';
- if(a[i][j].rf) c[2*i+1][2*j+2] = ' ';
- if(a[i][j].df) c[2*i+2][2*j+1] = ' ';
- if(a[i][j].uf) c[2*i][2*j+1] = ' ';
- }
- }
- }
- for(i=0;i<(2*n+1);i++){
- for(j=0;j<(2*m+1);j++){
- fprintf(f,"%c ",c[i][j]);
- }
- free(c[i]);
- fprintf(f,"\n");
- }
- free(c);
- fclose(f);
- }
- }
- void ispis2(Polje **a,int n, int m){
- int i,j;
- char **c;
- c = malloc((2*n+1)*sizeof(*c));
- for(i=0;i<(2*n+1);i++)
- c[i] = malloc((2*m+1)*sizeof(*c[i]));
- for(i=0;i<(2*n+1);i++)
- for(j=0;j<(2*m+1);j++)
- c[i][j] = '*';
- /*for(i=0;i<n;i++){
- for(j=0;j<m;j++){
- if(a[i][j].enabled){
- c[2*i+1][2*j+1] = a[i][j].znak;
- /*if(a[i][j].lf) c[2*i+1][2*j] = ' ';
- if(a[i][j].rf) c[2*i+1][2*j+2] = ' ';
- if(a[i][j].df) c[2*i+2][2*j+1] = ' ';
- if(a[i][j].uf) c[2*i][2*j+1] = ' ';
- }
- }
- }*/ // ================================================obrisao kod pasajlica
- for(i=0;i<(2*n+1);i++){
- for(j=0;j<(2*m+1);j++){
- printf("%c ",c[i][j]);
- }
- free(c[i]);
- printf("\n");
- }
- free(c);
- putchar('\n');
- }
- void print(Polje **polje,int n,int m){
- printf("print\n");
- int i,j;
- for(i=0;i<n;i++){
- for(j=0;j<m;j++){
- printf("%d ",polje[i][j].enabled);
- }
- printf("\n");
- }
- }
- Polje **initGraph(int n, int m){
- Polje **polje;
- int i;
- //polje = calloc(n,sizeof(*polje));
- CALLOCATE(polje,n,sizeof(*polje))
- for(i=0;i<n;i++)
- //polje[i] = calloc(m,sizeof(*polje[i]));
- CALLOCATE(polje[i],m,sizeof(*polje[i]))
- return polje;
- }
- Polje **initGraph1(int n, int m){
- Polje **polje;
- int i;
- //polje = calloc(n,sizeof(*polje));
- REALLOCATE(polje,n*sizeof(*polje))
- for(i=0;i<n;i++)
- //polje[i] = calloc(m,sizeof(*polje[i]));
- REALLOCATE(polje[i],m*sizeof(*polje[i]))
- return polje;
- }
- void initGraph2(Polje **polje,int n, int m){
- int i,j;
- polje = calloc(n,sizeof(*polje));
- for(i=0;i<n;i++)
- polje[i] = calloc(m,sizeof(*polje[i]));
- for(i=0;i<n;i++)
- for(j=0;j<m;j++)
- polje[i][j].enabled = 1;
- }
- void deleteGraph(Polje **a, int n, int m){
- int i,j;
- for(i=0;i<n;i++)
- for(j=0;j<m;j++)
- //removeNode(a,i,j,n,m);
- if(i<n && j<m && i>=0 && j>=0){
- a[i][j].enabled = 0;
- if(a[i][j].rf){a[i][j].rf = 0; a[i][j+1].lf = 0;}
- if(a[i][j].lf){a[i][j].lf = 0; a[i][j-1].rf = 0;}
- if(a[i][j].df){a[i][j].df = 0; a[i+1][j].uf = 0;}
- if(a[i][j].uf){a[i][j].uf = 0; a[i-1][j].df = 0;}
- }
- }
- void freeGraph(Polje **a,int n){
- int i;
- //printf("sao");
- for(i=0;i<n;i++)
- free(a[i]);
- //printf("FEGEWEGE");
- free(a);
- }
- int addBranch(Polje **a,int x1, int y1,int x2, int y2, int n, int m){
- if(x1<n && y1<m && x2<n && y2<m && x1>=0 && y1>=0 && x2>=0 && y2>=0 && a[x1][y1].enabled && a[x2][y2].enabled){
- if(y1-y2 == 1){
- a[x1][y1].lf = 1;
- a[x2][y2].rf = 1;
- }else
- if(y1-y2 == -1){
- a[x1][y1].rf = 1;
- a[x2][y2].lf = 1;
- }else
- if(x1-x2 == 1){
- a[x1][y1].uf = 1;
- a[x2][y2].df = 1;
- }else
- if(x1-x2 == -1){
- a[x1][y1].df = 1;
- a[x2][y2].uf = 1;
- }
- return 1;
- }
- return 0;
- }
- int removeBranch(Polje **a,int x1, int y1,int x2, int y2, int n, int m){
- if(x1<n && y1<m && x2<n && y2<m && x1>=0 && y1>=0 && x2>=0 && y2>=0 && a[x1][y1].enabled && a[x2][y2].enabled){
- if(y1-y2 == 1){
- a[x1][y1].lf = 0;
- a[x2][y2].rf = 0;
- }else
- if(y1-y2 == -1){
- a[x1][y1].rf = 0;
- a[x2][y2].lf = 0;
- }else
- if(x1-x2 == 1){
- a[x1][y1].uf = 0;
- a[x2][y2].df = 0;
- }else
- if(x1-x2 == -1){
- a[x1][y1].df = 0;
- a[x2][y2].uf = 0;
- }
- return 1;
- }
- return 0;
- }
- void addNode(Polje **a,int x1, int y1, int n, int m){
- if(x1<n && y1<m && x1>=0 && y1>=0){
- a[x1][y1].enabled = 1;
- }
- }
- void removeNode(Polje **a,int x1, int y1, int n, int m){
- if(x1<n && y1<m && x1>=0 && y1>=0){
- a[x1][y1].enabled = 0;
- if(a[x1][y1].rf){a[x1][y1].rf = 0; a[x1][y1+1].lf = 0;}
- if(a[x1][y1].lf){a[x1][y1].lf = 0; a[x1][y1-1].rf = 0;}
- if(a[x1][y1].df){a[x1][y1].df = 0; a[x1+1][y1].uf = 0;}
- if(a[x1][y1].uf){a[x1][y1].uf = 0; a[x1-1][y1].df = 0;}
- }
- }
- int enabled(Polje a){
- if(a.enabled)
- if(a.rf && a.lf && a.df && a.uf) return 0;
- return 1;
- }
- void Prim(Polje **a,int n, int m){
- int x,y,i;
- x = rand()%n;
- y = rand()%m;
- int t = n*m,cnt = 1;
- Lavirint *lavirint;
- //lavirint = malloc(n*m*sizeof(*lavirint));
- MALLOCATE(lavirint,(m*n)*sizeof(*lavirint))
- a[x][y].enabled = 1;
- lavirint[0].x = x;
- lavirint[0].y = y;
- //printf("lavr= %d; \n",a[x][y].enabled);
- //printf("lavr= %d; \n",lavirint[0].polje.enabled);
- int brojac=0;
- for(i=1;i<t;i++){
- //if(i>t) i=t;
- x = rand()%i;
- while(!enabled(a[lavirint[x].x][lavirint[x].y])){
- x=rand()%i;
- //putchar('a'); ///////////aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
- }
- //putchar('\n');
- y = rand()%4;
- switch(y){
- case 0: //lf
- if(lavirint[x].y==0) i--;
- else{
- if(!a[lavirint[x].x][lavirint[x].y - 1].enabled){
- lavirint[cnt].x = lavirint[x].x; //postavi novi cvor
- lavirint[cnt].y = lavirint[x].y - 1; ////////////////
- a[lavirint[cnt].x][lavirint[cnt].y].enabled = 1; // setuj ga
- a[lavirint[cnt].x][lavirint[cnt].y].rf = 1; // setuj mu granu
- a[lavirint[x].x][lavirint[x].y].lf = 1; // setuj granu posecenog cvora na novi
- cnt++; // dalje
- }else i--;
- }
- break;
- case 1: //rf
- if(lavirint[x].y==m-1) i--;
- else{
- if(!a[lavirint[x].x][lavirint[x].y + 1].enabled){
- lavirint[cnt].x = lavirint[x].x; //postavi novi cvor
- lavirint[cnt].y = lavirint[x].y + 1; ////////////////
- a[lavirint[cnt].x][lavirint[cnt].y].enabled = 1; // setuj ga
- a[lavirint[cnt].x][lavirint[cnt].y].lf = 1; // setuj mu granu
- a[lavirint[x].x][lavirint[x].y].rf = 1; // setuj granu posecenog cvora na novi
- cnt++; // dalje
- }else i--;
- }
- break;
- case 2: //df
- if(lavirint[x].x==n-1) i--;
- else{
- if(!a[lavirint[x].x + 1][lavirint[x].y].enabled){
- lavirint[cnt].x = lavirint[x].x + 1; //postavi novi cvor
- lavirint[cnt].y = lavirint[x].y; ////////////////
- a[lavirint[cnt].x][lavirint[cnt].y].enabled = 1; // setuj ga
- a[lavirint[cnt].x][lavirint[cnt].y].uf = 1; // setuj mu granu
- a[lavirint[x].x][lavirint[x].y].df = 1; // setuj granu posecenog cvora na novi
- cnt++; // dalje
- }else i--;
- }
- break;
- case 3: //uf
- if(lavirint[x].x==0) i--;
- else{
- if(!a[lavirint[x].x - 1][lavirint[x].y].enabled){
- lavirint[cnt].x = lavirint[x].x-1; //postavi novi cvor
- lavirint[cnt].y = lavirint[x].y; ////////////////
- a[lavirint[cnt].x][lavirint[cnt].y].enabled = 1; // setuj ga
- a[lavirint[cnt].x][lavirint[cnt].y].df = 1; // setuj mu granu
- a[lavirint[x].x][lavirint[x].y].uf = 1; // setuj granu posecenog cvora na novi
- cnt++; // dalje
- }else i--;
- }
- break;
- }
- }
- free(lavirint);
- }
- int bfs(Polje **a, int x1, int y1, int x2, int y2, int n, int m){
- Lavirint *lavirint;
- //lavirint = malloc(n*m*sizeof(*lavirint));
- MALLOCATE(lavirint,(m*n)*sizeof(*lavirint))
- lavirint[0].x = x1;
- lavirint[0].y = y1;
- int *visited;
- //visited = calloc(n*m,sizeof(*visited));
- CALLOCATE(visited,(n*m),sizeof(*visited))
- visited[m*x1+y1] = 1;
- int cnt = 1,i = 0,nasao = 0, turn=1, dodao= 0 , pdodao= 0 ,j;
- a[lavirint[i].x][lavirint[i].y].number = 0;
- while(i<cnt && !nasao){
- if(x2 == lavirint[i].x && y2 == lavirint[i].y){
- nasao = 1;
- break;
- }
- if(a[lavirint[i].x][lavirint[i].y].rf && !visited[m*lavirint[i].x+lavirint[i].y+1]){
- lavirint[cnt].x = lavirint[i].x;
- lavirint[cnt].y = lavirint[i].y + 1;
- a[lavirint[cnt].x][lavirint[cnt].y].number = turn;
- cnt++;
- dodao++;
- }
- if(a[lavirint[i].x][lavirint[i].y].lf && !visited[m*lavirint[i].x+lavirint[i].y-1]){
- lavirint[cnt].x = lavirint[i].x;
- lavirint[cnt].y = lavirint[i].y - 1;
- a[lavirint[cnt].x][lavirint[cnt].y].number = turn;
- cnt++;
- dodao++;
- }
- if(a[lavirint[i].x][lavirint[i].y].df && !visited[m*(lavirint[i].x+1)+lavirint[i].y]){
- lavirint[cnt].x = lavirint[i].x + 1;
- lavirint[cnt].y = lavirint[i].y;
- a[lavirint[cnt].x][lavirint[cnt].y].number = turn;
- cnt++;
- dodao++;
- }
- if(a[lavirint[i].x][lavirint[i].y].uf && !visited[m*(lavirint[i].x-1)+lavirint[i].y]){
- lavirint[cnt].x = lavirint[i].x - 1;
- lavirint[cnt].y = lavirint[i].y;
- a[lavirint[cnt].x][lavirint[cnt].y].number = turn;
- cnt++;
- dodao++;
- }
- visited[m*lavirint[i].x+lavirint[i].y] = 1;
- i++;
- if(!pdodao){
- turn++;
- pdodao=dodao;
- dodao = 0;
- }
- pdodao--;
- }
- if(nasao){
- FILE *f = stdout;
- printf("Upisati u datoteku? (0-da)");
- scanf("%d",&datyt);
- if(!datyt)
- {
- f = fopen("rezultati.txt","w");
- }
- int pomocni = i;
- char **c;
- //c = malloc((2*n+1)*sizeof(*c));
- MALLOCATE(c,(2*n+1)*sizeof(*c))
- for(i=0;i<(2*n+1);i++)
- //c[i] = malloc((2*m+1)*sizeof(*c[i]));
- MALLOCATE(c[i],(2*m+1)*sizeof(*c[i]))
- for(i=0;i<(2*n+1);i++)
- for(j=0;j<(2*m+1);j++)
- c[i][j] = '*';
- for(i=0;i<n;i++){
- for(j=0;j<m;j++){
- if(a[i][j].enabled){
- c[2*i+1][2*j+1] = ' ';
- if(a[i][j].lf) c[2*i+1][2*j] = ' ';
- if(a[i][j].rf) c[2*i+1][2*j+2] = ' ';
- if(a[i][j].df) c[2*i+2][2*j+1] = ' ';
- if(a[i][j].uf) c[2*i][2*j+1] = ' ';
- }
- }
- }
- /*for(i=0;i<(2*n+1);i++){
- for(j=0;j<(2*m+1);j++){
- printf("%c ",c[i][j]);
- }
- free(c[i]);
- printf("\n");
- }
- free(c);
- putchar('\n');*/
- i = pomocni;
- // a[lavirint[i].x][lavirint[i].y].znak = '@'; istpppppppp
- int x,y,pom;
- pom = a[lavirint[i].x][lavirint[i].y].number - 1;
- x = lavirint[i].x;
- y = lavirint[i].y;
- fprintf(f,"a\n");
- //while(x!=x1 && y!=y1){
- while(pom>=0){
- fprintf(f,"b%d\n",a[x][y].number);
- c[2*x+1][2*y+1] = '@';
- /*for(i=0;i<(2*n+1);i++){
- for(j=0;j<(2*m+1);j++){
- printf("%c ",c[i][j]);
- }
- printf("\n");
- }*/
- if(y>0 && a[x][y-1].number == pom && a[x][y].lf){
- //a[x][y-1].znak = '@';
- //c[2*x+1][2*y+1] = '@';
- c[2*x+1][2*y] = '@';
- y = y-1;
- }else
- if(y<m-1 && a[x][y+1].number == pom && a[x][y].rf){
- //a[x][y+1].znak = '@';
- //c[2*x+1][2*y+1] = '@';
- c[2*x+1][2*y+2] = '@';
- y = y+1;
- }else
- if(x>0 && a[x-1][y].number == pom && a[x][y].uf){
- //a[x-1][y].znak = '@';
- //c[2*x+1][2*y+1] = '@';
- c[2*x][2*y+1] = '@';
- x = x-1;
- }else
- if(x<n-1 && a[x+1][y].number == pom && a[x][y].df){
- //a[x+1][y].znak = '@';
- //c[2*x+1][2*y+1] = '@';
- c[2*x+2][2*y+1] = '@';
- x = x+1;
- }
- pom--;
- }
- c[2*x1+1][2*y1+1] = '@';
- //ispis2(a,n,m);
- fprintf(f,"Ispis: \n");
- for(i=0;i<(2*n+1);i++){
- for(j=0;j<(2*m+1);j++){
- fprintf(f,"%c ",c[i][j]);
- }
- free(c[i]);
- fprintf(f,"\n");
- }
- free(c);
- for(i=0;i<n;i++){
- for(j=0;j<m;j++){
- fprintf(f,"%d ",a[i][j].number);
- }
- fprintf(f,"\n");
- }
- if(!datyt)
- fclose(f);
- }
- free(lavirint);
- free(visited);
- return nasao;
- }
- void start(){
- printf("Ovo je program koji realizuje operacije za lavirint. Izaberite opciju... \n");
- }
- int postojiP=0;
- int meni(Polje **polje,int *n, int *m,int *ulazx,int *ulazy,int izlazx[],int izlazy[], int *nz){
- printf("1. Stvaranje grafa \n");
- printf("2. Dodavanje cvorova \n");
- printf("3. Dodavanje grane \n");
- printf("4. Brisanje cvora \n");
- printf("5. Brisanje grana \n");
- printf("6. Brisanje grafa \n");
- printf("7. Stvori lavirint(Prim) \n");
- printf("8. Definisi ulaz \n");
- printf("9. Definisi izlaz \n");
- printf("10.Ispis lavirinta \n");
- printf("11.Resi lavirint(ulaz-izlaz) \n");
- printf("12.Resi lavirint(proizvoljno) \n");
- printf("13.Kraj \n");
- int sol=13;
- scanf("%d",&sol);
- int x=-1,y=-1,x2=-1,y2=-1,i,j;
- char dos;
- switch(sol){
- case 1:
- if(!graf){
- printf("Unesite dimenzije: \n");
- scanf("%d %d",n,m);
- //graf = 1;
- polje = initGraph(*n,*m);
- }else{
- printf("Graf je vec postojao, ali sad je izbrisan. Stvorite ga ponovo ... \n");
- graf = 0;
- //freeGraph(polje,*n);
- }
- //initGraph2(polje,n,m);
- /*char **c;
- c = malloc((2*n+1)*sizeof(*c));
- for(i=0;i<(2*n+1);i++)
- c[i] = malloc((2*m+1)*sizeof(*c[i]));
- for(i=0;i<(2*n+1);i++)
- for(j=0;j<(2*m+1);j++)
- c[i][j] = '*';
- for(i=0;i<n;i++){
- for(j=0;j<m;j++){
- //printf("usao");
- if(polje[i][j].enabled){
- //printf("usao2");
- if(i==ulazx && j==ulazy)
- c[2*i+1][2*j+1] = 'O';
- else c[2*i+1][2*j+1] = ' ';
- int ii;
- for(ii=0;ii<nz;ii++)
- if(izlazx[ii] == i && izlazy[ii] == j)
- c[2*i+1][2*j+1] = 'X';
- if(polje[i][j].lf) c[2*i+1][2*j] = ' ';
- if(polje[i][j].rf) c[2*i+1][2*j+2] = ' ';
- if(polje[i][j].df) c[2*i+2][2*j+1] = ' ';
- if(polje[i][j].uf) c[2*i][2*j+1] = ' ';
- }
- }
- }
- for(i=0;i<(2*n+1);i++){
- for(j=0;j<(2*m+1);j++){
- printf("%c ",c[i][j]);
- }
- free(c[i]);
- printf("\n");
- }
- free(c);
- putchar('\n');*/
- //ispis(polje,n,m,ulazx,ulazy,izlazx,izlazy,nz);
- break;
- case 2:
- printf("Unesite koordinate cvora: \n");
- scanf("%d %d",&x,&y);
- addNode(polje,x,y,*n,*m);
- break;
- case 3:
- printf("Unesite koordinate cvorova: \n");
- scanf("%d %d %d %d",&x,&y,&x2,&y2);
- addBranch(polje,x, y, x2, y2,*n,*m);
- break;
- case 4:
- printf("Unesite koordinate cvora: \n");
- scanf("%d %d",&x,&y);
- removeNode(polje,x,y,*n,*m);
- break;
- case 5:
- printf("Unesite koordinate cvorova: \n");
- scanf("%d %d %d %d",&x,&y,&x2,&y2);
- removeBranch(polje,x,y,x2,y2,*n,*m);
- break;
- case 6:
- postojiP = 0;
- deleteGraph(polje,*n,*m);
- //freeGraph(polje,*n);
- break;
- case 7:
- if(postojiP) {
- printf("Vec postoji, izbrisite ga za ponovno stvaranje ... \n");
- }
- else{
- postojiP = 1;
- Prim(polje,*n,*m);
- }
- break;
- case 8:
- printf("Unesite koordinate cvora: \n");
- scanf("%d %d",ulazx,ulazy);
- break;
- case 9:
- printf("Koliko izlaza zelite? \n");
- scanf("%d",nz);
- for(i=0;i<*nz;i++){
- printf("Unesite koordinate cvora: \n");
- scanf("%d %d",&izlazx[i],&izlazy[i]);
- }
- break;
- case 10:
- //printf("usao");
- printf("Ispis u datoteku?(0-da)\n");
- scanf("%d",&datyt);
- //if(dos=='y') dat = 1;
- //else dat = 0;
- ispis(polje,*n,*m,*ulazx,*ulazy,izlazx,izlazy,*nz);
- break;
- case 11:
- printf("Unesite broj izlaza: \n");
- scanf("%d",&i);
- bfs(polje,*ulazx,*ulazy,izlazx[i],izlazy[i],*n,*m);
- break;
- case 12:
- printf("Unesite koordinate cvorova: \n");
- scanf("%d %d %d %d",&x,&y,&x2,&y2);
- bfs(polje,x,y,x2,y2,*n,*m);
- break;
- case 13:
- return 0;
- break;
- }
- return 1;
- }
- int main(){
- srand(time(0));
- Polje **polje = NULL;
- int i,j;
- int ulazx=-1,ulazy=-1,izlazx[100]={-1},izlazy[100]={-1},nz=-1;
- int n=300,m=300;
- start();
- polje = initGraph(n,m);
- //graf = 1;
- while(meni(polje,&n,&m,&ulazx,&ulazy,izlazx,izlazy,&nz));
- /*polje = initGraph(n,m);
- addNode(polje,2,2,n,m);
- addNode(polje,2,1,n,m);
- addBranch(polje,2, 2, 2, 1,n,m);
- addNode(polje,2,0,n,m);
- addBranch(polje,2, 1, 2, 0,n,m);
- addNode(polje,1,1,n,m);
- addBranch(polje,2, 1, 1, 1,n,m);
- ispis(polje,n,m);
- removeBranch(polje,2, 1, 1, 1,n,m);
- ispis(polje,n,m);
- removeNode(polje,2,1,n,m);
- for(i=0;i<n;i++){
- for(j=0;j<m;j++){
- printf("%d ",polje[i][j].enabled);
- }
- printf("\n");
- }
- putchar('\n');
- ispis(polje,n,m);
- deleteGraph(polje,n,m);
- ispis(polje,n,m);
- for(i=0;i<n;i++){
- for(j=0;j<m;j++){
- printf("%d ",polje[i][j].enabled);
- }
- printf("\n");
- }
- Prim(polje,n,m);
- ispis(polje,n,m);
- for(i=0;i<n;i++){
- for(j=0;j<m;j++){
- printf("%d ",polje[i][j].enabled);
- }
- printf("\n");
- }
- int x1,y1,x2,y2;
- scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
- printf("%d",bfs(polje,x1,y1,x2,y2,n,m));*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement