Advertisement
Guest User

gsgzegs

a guest
May 28th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.13 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <time.h>
  5. #define MALLOCATE(p,size) { p = malloc(size); if(!p) {printf("Nedovoljno memorije"); exit(1); }}
  6. #define CALLOCATE(p,n,size) { p = calloc(n,size); if(!p) {printf("Nedovoljno memorije"); exit(1); }}
  7. #define REALLOCATE(p,size) { p = realloc(p,size); if(!p) {printf("Nedovoljno memorije"); exit(1); }}
  8.  
  9.  
  10. typedef struct{
  11. int number;
  12. int enabled;
  13. int lf,rf,df,uf;
  14. }Polje;
  15.  
  16. typedef struct{
  17. int x,y;
  18. }Lavirint;
  19.  
  20. int datyt = 1;
  21. int graf = 0;
  22.  
  23. void ispis(Polje **a,int n, int m,int ulazx,int ulazy,int izlazx[],int izlazy[], int nz){
  24. //printf("uso");
  25.  
  26.  
  27.  
  28. if(datyt)
  29. {
  30. //printf("uso1");
  31. int i,j;
  32. char **c;
  33. //c = malloc((2*n+1)*sizeof(*c));
  34. MALLOCATE(c,(2*n+1)*sizeof(*c))
  35.  
  36. for(i=0;i<(2*n+1);i++)
  37. //c[i] = malloc((2*m+1)*sizeof(*c[i]));
  38. MALLOCATE(c[i],(2*m+1)*sizeof(*c[i]))
  39.  
  40. //printf("usoOOOOOOO");
  41. for(i=0;i<(2*n+1);i++)
  42. for(j=0;j<(2*m+1);j++)
  43. c[i][j] = '*';
  44.  
  45. for(i=0;i<n;i++){
  46. for(j=0;j<m;j++){
  47. //printf("usao");
  48. //printf("PIH1");
  49. if(a[i][j].enabled){
  50. //printf("usao2");
  51. //printf("PIH2");
  52. if(i==ulazx && j==ulazy)
  53. c[2*i+1][2*j+1] = 'O';
  54. else c[2*i+1][2*j+1] = ' ';
  55. int ii;
  56. for(ii=0;ii<nz;ii++)
  57. if(izlazx[ii] == i && izlazy[ii] == j)
  58. c[2*i+1][2*j+1] = 'X';
  59. if(a[i][j].lf) c[2*i+1][2*j] = ' ';
  60. if(a[i][j].rf) c[2*i+1][2*j+2] = ' ';
  61. if(a[i][j].df) c[2*i+2][2*j+1] = ' ';
  62. if(a[i][j].uf) c[2*i][2*j+1] = ' ';
  63. }
  64. }
  65. }
  66.  
  67.  
  68. for(i=0;i<(2*n+1);i++){
  69. for(j=0;j<(2*m+1);j++){
  70. printf("%c ",c[i][j]);
  71. }
  72. free(c[i]);
  73. printf("\n");
  74. }
  75. free(c);
  76. putchar('\n');
  77. }else {
  78. //printf("uso2");
  79. FILE *f = fopen("rezultati.txt","w");
  80. int i,j;
  81. char **c;
  82. //printf("uso3");
  83. //c = malloc((2*n+1)*sizeof(*c));
  84. MALLOCATE(c,(2*n+1)*sizeof(*c))
  85.  
  86. for(i=0;i<(2*n+1);i++)
  87. //c[i] = malloc((2*m+1)*sizeof(*c[i]));
  88. MALLOCATE(c[i],(2*m+1)*sizeof(*c[i]))
  89. for(i=0;i<(2*n+1);i++)
  90. for(j=0;j<(2*m+1);j++)
  91. c[i][j] = '*';
  92.  
  93. for(i=0;i<n;i++){
  94. for(j=0;j<m;j++){
  95. //printf("usao");
  96. if(a[i][j].enabled){
  97. //printf("usao2");
  98. if(i==ulazx && j==ulazy)
  99. c[2*i+1][2*j+1] = 'O';
  100. else c[2*i+1][2*j+1] = ' ';
  101. int ii;
  102. for(ii=0;ii<nz;ii++)
  103. if(izlazx[ii] == i && izlazy[ii] == j)
  104. c[2*i+1][2*j+1] = 'X';
  105. if(a[i][j].lf) c[2*i+1][2*j] = ' ';
  106. if(a[i][j].rf) c[2*i+1][2*j+2] = ' ';
  107. if(a[i][j].df) c[2*i+2][2*j+1] = ' ';
  108. if(a[i][j].uf) c[2*i][2*j+1] = ' ';
  109. }
  110. }
  111. }
  112.  
  113.  
  114. for(i=0;i<(2*n+1);i++){
  115. for(j=0;j<(2*m+1);j++){
  116. fprintf(f,"%c ",c[i][j]);
  117. }
  118. free(c[i]);
  119. fprintf(f,"\n");
  120. }
  121. free(c);
  122. fclose(f);
  123. }
  124. }
  125.  
  126.  
  127. void ispis2(Polje **a,int n, int m){
  128. int i,j;
  129. char **c;
  130. c = malloc((2*n+1)*sizeof(*c));
  131. for(i=0;i<(2*n+1);i++)
  132. c[i] = malloc((2*m+1)*sizeof(*c[i]));
  133. for(i=0;i<(2*n+1);i++)
  134. for(j=0;j<(2*m+1);j++)
  135. c[i][j] = '*';
  136.  
  137. /*for(i=0;i<n;i++){
  138. for(j=0;j<m;j++){
  139. if(a[i][j].enabled){
  140. c[2*i+1][2*j+1] = a[i][j].znak;
  141. /*if(a[i][j].lf) c[2*i+1][2*j] = ' ';
  142. if(a[i][j].rf) c[2*i+1][2*j+2] = ' ';
  143. if(a[i][j].df) c[2*i+2][2*j+1] = ' ';
  144. if(a[i][j].uf) c[2*i][2*j+1] = ' ';
  145. }
  146. }
  147. }*/ // ================================================obrisao kod pasajlica
  148.  
  149.  
  150. for(i=0;i<(2*n+1);i++){
  151. for(j=0;j<(2*m+1);j++){
  152. printf("%c ",c[i][j]);
  153. }
  154. free(c[i]);
  155. printf("\n");
  156. }
  157. free(c);
  158. putchar('\n');
  159. }
  160.  
  161. void print(Polje **polje,int n,int m){
  162. printf("print\n");
  163. int i,j;
  164. for(i=0;i<n;i++){
  165. for(j=0;j<m;j++){
  166. printf("%d ",polje[i][j].enabled);
  167. }
  168. printf("\n");
  169. }
  170.  
  171. }
  172.  
  173. Polje **initGraph(int n, int m){
  174. Polje **polje;
  175. int i;
  176. //polje = calloc(n,sizeof(*polje));
  177. CALLOCATE(polje,n,sizeof(*polje))
  178. for(i=0;i<n;i++)
  179. //polje[i] = calloc(m,sizeof(*polje[i]));
  180. CALLOCATE(polje[i],m,sizeof(*polje[i]))
  181. return polje;
  182. }
  183.  
  184.  
  185. Polje **initGraph1(int n, int m){
  186. Polje **polje;
  187. int i;
  188. //polje = calloc(n,sizeof(*polje));
  189. REALLOCATE(polje,n*sizeof(*polje))
  190. for(i=0;i<n;i++)
  191. //polje[i] = calloc(m,sizeof(*polje[i]));
  192. REALLOCATE(polje[i],m*sizeof(*polje[i]))
  193. return polje;
  194. }
  195.  
  196.  
  197. void initGraph2(Polje **polje,int n, int m){
  198. int i,j;
  199. polje = calloc(n,sizeof(*polje));
  200. for(i=0;i<n;i++)
  201. polje[i] = calloc(m,sizeof(*polje[i]));
  202. for(i=0;i<n;i++)
  203. for(j=0;j<m;j++)
  204. polje[i][j].enabled = 1;
  205. }
  206.  
  207. void deleteGraph(Polje **a, int n, int m){
  208. int i,j;
  209. for(i=0;i<n;i++)
  210. for(j=0;j<m;j++)
  211. //removeNode(a,i,j,n,m);
  212. if(i<n && j<m && i>=0 && j>=0){
  213. a[i][j].enabled = 0;
  214. if(a[i][j].rf){a[i][j].rf = 0; a[i][j+1].lf = 0;}
  215. if(a[i][j].lf){a[i][j].lf = 0; a[i][j-1].rf = 0;}
  216. if(a[i][j].df){a[i][j].df = 0; a[i+1][j].uf = 0;}
  217. if(a[i][j].uf){a[i][j].uf = 0; a[i-1][j].df = 0;}
  218. }
  219. }
  220.  
  221.  
  222.  
  223. void freeGraph(Polje **a,int n){
  224. int i;
  225. //printf("sao");
  226. for(i=0;i<n;i++)
  227. free(a[i]);
  228. //printf("FEGEWEGE");
  229. free(a);
  230. }
  231.  
  232. int addBranch(Polje **a,int x1, int y1,int x2, int y2, int n, int m){
  233. 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){
  234. if(y1-y2 == 1){
  235. a[x1][y1].lf = 1;
  236. a[x2][y2].rf = 1;
  237. }else
  238. if(y1-y2 == -1){
  239. a[x1][y1].rf = 1;
  240. a[x2][y2].lf = 1;
  241. }else
  242. if(x1-x2 == 1){
  243. a[x1][y1].uf = 1;
  244. a[x2][y2].df = 1;
  245. }else
  246. if(x1-x2 == -1){
  247. a[x1][y1].df = 1;
  248. a[x2][y2].uf = 1;
  249. }
  250. return 1;
  251. }
  252. return 0;
  253. }
  254.  
  255.  
  256. int removeBranch(Polje **a,int x1, int y1,int x2, int y2, int n, int m){
  257. 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){
  258. if(y1-y2 == 1){
  259. a[x1][y1].lf = 0;
  260. a[x2][y2].rf = 0;
  261. }else
  262. if(y1-y2 == -1){
  263. a[x1][y1].rf = 0;
  264. a[x2][y2].lf = 0;
  265. }else
  266. if(x1-x2 == 1){
  267. a[x1][y1].uf = 0;
  268. a[x2][y2].df = 0;
  269. }else
  270. if(x1-x2 == -1){
  271. a[x1][y1].df = 0;
  272. a[x2][y2].uf = 0;
  273. }
  274. return 1;
  275. }
  276. return 0;
  277. }
  278.  
  279. void addNode(Polje **a,int x1, int y1, int n, int m){
  280. if(x1<n && y1<m && x1>=0 && y1>=0){
  281. a[x1][y1].enabled = 1;
  282. }
  283. }
  284.  
  285. void removeNode(Polje **a,int x1, int y1, int n, int m){
  286. if(x1<n && y1<m && x1>=0 && y1>=0){
  287. a[x1][y1].enabled = 0;
  288. if(a[x1][y1].rf){a[x1][y1].rf = 0; a[x1][y1+1].lf = 0;}
  289. if(a[x1][y1].lf){a[x1][y1].lf = 0; a[x1][y1-1].rf = 0;}
  290. if(a[x1][y1].df){a[x1][y1].df = 0; a[x1+1][y1].uf = 0;}
  291. if(a[x1][y1].uf){a[x1][y1].uf = 0; a[x1-1][y1].df = 0;}
  292. }
  293. }
  294.  
  295. int enabled(Polje a){
  296. if(a.enabled)
  297. if(a.rf && a.lf && a.df && a.uf) return 0;
  298. return 1;
  299. }
  300.  
  301. void Prim(Polje **a,int n, int m){
  302. int x,y,i;
  303. x = rand()%n;
  304. y = rand()%m;
  305. int t = n*m,cnt = 1;
  306. Lavirint *lavirint;
  307. //lavirint = malloc(n*m*sizeof(*lavirint));
  308. MALLOCATE(lavirint,(m*n)*sizeof(*lavirint))
  309. a[x][y].enabled = 1;
  310. lavirint[0].x = x;
  311. lavirint[0].y = y;
  312. //printf("lavr= %d; \n",a[x][y].enabled);
  313. //printf("lavr= %d; \n",lavirint[0].polje.enabled);
  314. int brojac=0;
  315. for(i=1;i<t;i++){
  316. //if(i>t) i=t;
  317. x = rand()%i;
  318. while(!enabled(a[lavirint[x].x][lavirint[x].y])){
  319. x=rand()%i;
  320. //putchar('a'); ///////////aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  321. }
  322. //putchar('\n');
  323.  
  324. y = rand()%4;
  325. switch(y){
  326. case 0: //lf
  327. if(lavirint[x].y==0) i--;
  328. else{
  329. if(!a[lavirint[x].x][lavirint[x].y - 1].enabled){
  330. lavirint[cnt].x = lavirint[x].x; //postavi novi cvor
  331. lavirint[cnt].y = lavirint[x].y - 1; ////////////////
  332. a[lavirint[cnt].x][lavirint[cnt].y].enabled = 1; // setuj ga
  333. a[lavirint[cnt].x][lavirint[cnt].y].rf = 1; // setuj mu granu
  334. a[lavirint[x].x][lavirint[x].y].lf = 1; // setuj granu posecenog cvora na novi
  335. cnt++; // dalje
  336. }else i--;
  337. }
  338. break;
  339. case 1: //rf
  340. if(lavirint[x].y==m-1) i--;
  341. else{
  342. if(!a[lavirint[x].x][lavirint[x].y + 1].enabled){
  343. lavirint[cnt].x = lavirint[x].x; //postavi novi cvor
  344. lavirint[cnt].y = lavirint[x].y + 1; ////////////////
  345. a[lavirint[cnt].x][lavirint[cnt].y].enabled = 1; // setuj ga
  346. a[lavirint[cnt].x][lavirint[cnt].y].lf = 1; // setuj mu granu
  347. a[lavirint[x].x][lavirint[x].y].rf = 1; // setuj granu posecenog cvora na novi
  348. cnt++; // dalje
  349. }else i--;
  350. }
  351. break;
  352. case 2: //df
  353. if(lavirint[x].x==n-1) i--;
  354. else{
  355. if(!a[lavirint[x].x + 1][lavirint[x].y].enabled){
  356. lavirint[cnt].x = lavirint[x].x + 1; //postavi novi cvor
  357. lavirint[cnt].y = lavirint[x].y; ////////////////
  358.  
  359. a[lavirint[cnt].x][lavirint[cnt].y].enabled = 1; // setuj ga
  360. a[lavirint[cnt].x][lavirint[cnt].y].uf = 1; // setuj mu granu
  361. a[lavirint[x].x][lavirint[x].y].df = 1; // setuj granu posecenog cvora na novi
  362. cnt++; // dalje
  363. }else i--;
  364. }
  365. break;
  366. case 3: //uf
  367. if(lavirint[x].x==0) i--;
  368. else{
  369. if(!a[lavirint[x].x - 1][lavirint[x].y].enabled){
  370. lavirint[cnt].x = lavirint[x].x-1; //postavi novi cvor
  371. lavirint[cnt].y = lavirint[x].y; ////////////////
  372. a[lavirint[cnt].x][lavirint[cnt].y].enabled = 1; // setuj ga
  373. a[lavirint[cnt].x][lavirint[cnt].y].df = 1; // setuj mu granu
  374. a[lavirint[x].x][lavirint[x].y].uf = 1; // setuj granu posecenog cvora na novi
  375. cnt++; // dalje
  376. }else i--;
  377. }
  378. break;
  379. }
  380.  
  381. }
  382. free(lavirint);
  383. }
  384.  
  385.  
  386. int bfs(Polje **a, int x1, int y1, int x2, int y2, int n, int m){
  387. Lavirint *lavirint;
  388. //lavirint = malloc(n*m*sizeof(*lavirint));
  389. MALLOCATE(lavirint,(m*n)*sizeof(*lavirint))
  390. lavirint[0].x = x1;
  391. lavirint[0].y = y1;
  392. int *visited;
  393. //visited = calloc(n*m,sizeof(*visited));
  394. CALLOCATE(visited,(n*m),sizeof(*visited))
  395. visited[m*x1+y1] = 1;
  396. int cnt = 1,i = 0,nasao = 0, turn=1, dodao= 0 , pdodao= 0 ,j;
  397. a[lavirint[i].x][lavirint[i].y].number = 0;
  398. while(i<cnt && !nasao){
  399. if(x2 == lavirint[i].x && y2 == lavirint[i].y){
  400. nasao = 1;
  401. break;
  402. }
  403.  
  404. if(a[lavirint[i].x][lavirint[i].y].rf && !visited[m*lavirint[i].x+lavirint[i].y+1]){
  405. lavirint[cnt].x = lavirint[i].x;
  406. lavirint[cnt].y = lavirint[i].y + 1;
  407. a[lavirint[cnt].x][lavirint[cnt].y].number = turn;
  408. cnt++;
  409. dodao++;
  410. }
  411. if(a[lavirint[i].x][lavirint[i].y].lf && !visited[m*lavirint[i].x+lavirint[i].y-1]){
  412. lavirint[cnt].x = lavirint[i].x;
  413. lavirint[cnt].y = lavirint[i].y - 1;
  414. a[lavirint[cnt].x][lavirint[cnt].y].number = turn;
  415. cnt++;
  416. dodao++;
  417. }
  418. if(a[lavirint[i].x][lavirint[i].y].df && !visited[m*(lavirint[i].x+1)+lavirint[i].y]){
  419. lavirint[cnt].x = lavirint[i].x + 1;
  420. lavirint[cnt].y = lavirint[i].y;
  421. a[lavirint[cnt].x][lavirint[cnt].y].number = turn;
  422. cnt++;
  423. dodao++;
  424. }
  425. if(a[lavirint[i].x][lavirint[i].y].uf && !visited[m*(lavirint[i].x-1)+lavirint[i].y]){
  426. lavirint[cnt].x = lavirint[i].x - 1;
  427. lavirint[cnt].y = lavirint[i].y;
  428. a[lavirint[cnt].x][lavirint[cnt].y].number = turn;
  429. cnt++;
  430. dodao++;
  431. }
  432. visited[m*lavirint[i].x+lavirint[i].y] = 1;
  433. i++;
  434.  
  435. if(!pdodao){
  436. turn++;
  437. pdodao=dodao;
  438. dodao = 0;
  439. }
  440. pdodao--;
  441. }
  442. if(nasao){
  443. FILE *f = stdout;
  444. printf("Upisati u datoteku? (0-da)");
  445. scanf("%d",&datyt);
  446. if(!datyt)
  447. {
  448. f = fopen("rezultati.txt","w");
  449. }
  450. int pomocni = i;
  451.  
  452. char **c;
  453. //c = malloc((2*n+1)*sizeof(*c));
  454. MALLOCATE(c,(2*n+1)*sizeof(*c))
  455. for(i=0;i<(2*n+1);i++)
  456. //c[i] = malloc((2*m+1)*sizeof(*c[i]));
  457. MALLOCATE(c[i],(2*m+1)*sizeof(*c[i]))
  458. for(i=0;i<(2*n+1);i++)
  459. for(j=0;j<(2*m+1);j++)
  460. c[i][j] = '*';
  461.  
  462. for(i=0;i<n;i++){
  463. for(j=0;j<m;j++){
  464. if(a[i][j].enabled){
  465. c[2*i+1][2*j+1] = ' ';
  466. if(a[i][j].lf) c[2*i+1][2*j] = ' ';
  467. if(a[i][j].rf) c[2*i+1][2*j+2] = ' ';
  468. if(a[i][j].df) c[2*i+2][2*j+1] = ' ';
  469. if(a[i][j].uf) c[2*i][2*j+1] = ' ';
  470. }
  471. }
  472. }
  473.  
  474.  
  475. /*for(i=0;i<(2*n+1);i++){
  476. for(j=0;j<(2*m+1);j++){
  477. printf("%c ",c[i][j]);
  478. }
  479. free(c[i]);
  480. printf("\n");
  481. }
  482. free(c);
  483. putchar('\n');*/
  484.  
  485. i = pomocni;
  486.  
  487. // a[lavirint[i].x][lavirint[i].y].znak = '@'; istpppppppp
  488. int x,y,pom;
  489. pom = a[lavirint[i].x][lavirint[i].y].number - 1;
  490. x = lavirint[i].x;
  491. y = lavirint[i].y;
  492. fprintf(f,"a\n");
  493. //while(x!=x1 && y!=y1){
  494. while(pom>=0){
  495. fprintf(f,"b%d\n",a[x][y].number);
  496. c[2*x+1][2*y+1] = '@';
  497. /*for(i=0;i<(2*n+1);i++){
  498. for(j=0;j<(2*m+1);j++){
  499. printf("%c ",c[i][j]);
  500. }
  501. printf("\n");
  502. }*/
  503. if(y>0 && a[x][y-1].number == pom && a[x][y].lf){
  504. //a[x][y-1].znak = '@';
  505. //c[2*x+1][2*y+1] = '@';
  506. c[2*x+1][2*y] = '@';
  507. y = y-1;
  508. }else
  509. if(y<m-1 && a[x][y+1].number == pom && a[x][y].rf){
  510. //a[x][y+1].znak = '@';
  511. //c[2*x+1][2*y+1] = '@';
  512. c[2*x+1][2*y+2] = '@';
  513. y = y+1;
  514. }else
  515. if(x>0 && a[x-1][y].number == pom && a[x][y].uf){
  516. //a[x-1][y].znak = '@';
  517. //c[2*x+1][2*y+1] = '@';
  518. c[2*x][2*y+1] = '@';
  519. x = x-1;
  520. }else
  521. if(x<n-1 && a[x+1][y].number == pom && a[x][y].df){
  522. //a[x+1][y].znak = '@';
  523. //c[2*x+1][2*y+1] = '@';
  524. c[2*x+2][2*y+1] = '@';
  525. x = x+1;
  526. }
  527. pom--;
  528. }
  529. c[2*x1+1][2*y1+1] = '@';
  530.  
  531. //ispis2(a,n,m);
  532. fprintf(f,"Ispis: \n");
  533. for(i=0;i<(2*n+1);i++){
  534. for(j=0;j<(2*m+1);j++){
  535. fprintf(f,"%c ",c[i][j]);
  536. }
  537. free(c[i]);
  538. fprintf(f,"\n");
  539. }
  540. free(c);
  541.  
  542.  
  543.  
  544.  
  545. for(i=0;i<n;i++){
  546. for(j=0;j<m;j++){
  547. fprintf(f,"%d ",a[i][j].number);
  548. }
  549. fprintf(f,"\n");
  550. }
  551. if(!datyt)
  552. fclose(f);
  553.  
  554. }
  555. free(lavirint);
  556. free(visited);
  557. return nasao;
  558. }
  559.  
  560. void start(){
  561. printf("Ovo je program koji realizuje operacije za lavirint. Izaberite opciju... \n");
  562. }
  563.  
  564. int postojiP=0;
  565.  
  566. int meni(Polje **polje,int *n, int *m,int *ulazx,int *ulazy,int izlazx[],int izlazy[], int *nz){
  567. printf("1. Stvaranje grafa \n");
  568. printf("2. Dodavanje cvorova \n");
  569. printf("3. Dodavanje grane \n");
  570. printf("4. Brisanje cvora \n");
  571. printf("5. Brisanje grana \n");
  572. printf("6. Brisanje grafa \n");
  573. printf("7. Stvori lavirint(Prim) \n");
  574. printf("8. Definisi ulaz \n");
  575. printf("9. Definisi izlaz \n");
  576. printf("10.Ispis lavirinta \n");
  577. printf("11.Resi lavirint(ulaz-izlaz) \n");
  578. printf("12.Resi lavirint(proizvoljno) \n");
  579. printf("13.Kraj \n");
  580. int sol=13;
  581. scanf("%d",&sol);
  582. int x=-1,y=-1,x2=-1,y2=-1,i,j;
  583. char dos;
  584. switch(sol){
  585. case 1:
  586. if(!graf){
  587. printf("Unesite dimenzije: \n");
  588. scanf("%d %d",n,m);
  589. //graf = 1;
  590. polje = initGraph(*n,*m);
  591. }else{
  592. printf("Graf je vec postojao, ali sad je izbrisan. Stvorite ga ponovo ... \n");
  593. graf = 0;
  594. //freeGraph(polje,*n);
  595. }
  596. //initGraph2(polje,n,m);
  597. /*char **c;
  598. c = malloc((2*n+1)*sizeof(*c));
  599. for(i=0;i<(2*n+1);i++)
  600. c[i] = malloc((2*m+1)*sizeof(*c[i]));
  601. for(i=0;i<(2*n+1);i++)
  602. for(j=0;j<(2*m+1);j++)
  603. c[i][j] = '*';
  604.  
  605. for(i=0;i<n;i++){
  606. for(j=0;j<m;j++){
  607. //printf("usao");
  608. if(polje[i][j].enabled){
  609. //printf("usao2");
  610. if(i==ulazx && j==ulazy)
  611. c[2*i+1][2*j+1] = 'O';
  612. else c[2*i+1][2*j+1] = ' ';
  613. int ii;
  614. for(ii=0;ii<nz;ii++)
  615. if(izlazx[ii] == i && izlazy[ii] == j)
  616. c[2*i+1][2*j+1] = 'X';
  617. if(polje[i][j].lf) c[2*i+1][2*j] = ' ';
  618. if(polje[i][j].rf) c[2*i+1][2*j+2] = ' ';
  619. if(polje[i][j].df) c[2*i+2][2*j+1] = ' ';
  620. if(polje[i][j].uf) c[2*i][2*j+1] = ' ';
  621. }
  622. }
  623. }
  624.  
  625.  
  626. for(i=0;i<(2*n+1);i++){
  627. for(j=0;j<(2*m+1);j++){
  628. printf("%c ",c[i][j]);
  629. }
  630. free(c[i]);
  631. printf("\n");
  632. }
  633. free(c);
  634. putchar('\n');*/
  635. //ispis(polje,n,m,ulazx,ulazy,izlazx,izlazy,nz);
  636. break;
  637. case 2:
  638. printf("Unesite koordinate cvora: \n");
  639. scanf("%d %d",&x,&y);
  640. addNode(polje,x,y,*n,*m);
  641. break;
  642. case 3:
  643. printf("Unesite koordinate cvorova: \n");
  644. scanf("%d %d %d %d",&x,&y,&x2,&y2);
  645. addBranch(polje,x, y, x2, y2,*n,*m);
  646. break;
  647. case 4:
  648. printf("Unesite koordinate cvora: \n");
  649. scanf("%d %d",&x,&y);
  650. removeNode(polje,x,y,*n,*m);
  651. break;
  652. case 5:
  653. printf("Unesite koordinate cvorova: \n");
  654. scanf("%d %d %d %d",&x,&y,&x2,&y2);
  655. removeBranch(polje,x,y,x2,y2,*n,*m);
  656. break;
  657. case 6:
  658. postojiP = 0;
  659. deleteGraph(polje,*n,*m);
  660. //freeGraph(polje,*n);
  661. break;
  662. case 7:
  663. if(postojiP) {
  664. printf("Vec postoji, izbrisite ga za ponovno stvaranje ... \n");
  665. }
  666. else{
  667. postojiP = 1;
  668. Prim(polje,*n,*m);
  669. }
  670. break;
  671. case 8:
  672. printf("Unesite koordinate cvora: \n");
  673. scanf("%d %d",ulazx,ulazy);
  674. break;
  675. case 9:
  676. printf("Koliko izlaza zelite? \n");
  677. scanf("%d",nz);
  678. for(i=0;i<*nz;i++){
  679. printf("Unesite koordinate cvora: \n");
  680. scanf("%d %d",&izlazx[i],&izlazy[i]);
  681. }
  682. break;
  683. case 10:
  684. //printf("usao");
  685. printf("Ispis u datoteku?(0-da)\n");
  686. scanf("%d",&datyt);
  687. //if(dos=='y') dat = 1;
  688. //else dat = 0;
  689. ispis(polje,*n,*m,*ulazx,*ulazy,izlazx,izlazy,*nz);
  690. break;
  691. case 11:
  692. printf("Unesite broj izlaza: \n");
  693. scanf("%d",&i);
  694. bfs(polje,*ulazx,*ulazy,izlazx[i],izlazy[i],*n,*m);
  695. break;
  696. case 12:
  697. printf("Unesite koordinate cvorova: \n");
  698. scanf("%d %d %d %d",&x,&y,&x2,&y2);
  699. bfs(polje,x,y,x2,y2,*n,*m);
  700. break;
  701. case 13:
  702. return 0;
  703. break;
  704. }
  705. return 1;
  706. }
  707.  
  708.  
  709.  
  710.  
  711. int main(){
  712.  
  713. srand(time(0));
  714. Polje **polje = NULL;
  715. int i,j;
  716. int ulazx=-1,ulazy=-1,izlazx[100]={-1},izlazy[100]={-1},nz=-1;
  717. int n=300,m=300;
  718.  
  719. start();
  720. polje = initGraph(n,m);
  721. //graf = 1;
  722. while(meni(polje,&n,&m,&ulazx,&ulazy,izlazx,izlazy,&nz));
  723.  
  724.  
  725. /*polje = initGraph(n,m);
  726.  
  727. addNode(polje,2,2,n,m);
  728. addNode(polje,2,1,n,m);
  729. addBranch(polje,2, 2, 2, 1,n,m);
  730.  
  731. addNode(polje,2,0,n,m);
  732. addBranch(polje,2, 1, 2, 0,n,m);
  733. addNode(polje,1,1,n,m);
  734. addBranch(polje,2, 1, 1, 1,n,m);
  735.  
  736.  
  737. ispis(polje,n,m);
  738.  
  739. removeBranch(polje,2, 1, 1, 1,n,m);
  740.  
  741. ispis(polje,n,m);
  742.  
  743. removeNode(polje,2,1,n,m);
  744.  
  745.  
  746. for(i=0;i<n;i++){
  747. for(j=0;j<m;j++){
  748. printf("%d ",polje[i][j].enabled);
  749. }
  750. printf("\n");
  751. }
  752.  
  753. putchar('\n');
  754. ispis(polje,n,m);
  755. deleteGraph(polje,n,m);
  756. ispis(polje,n,m);
  757. for(i=0;i<n;i++){
  758. for(j=0;j<m;j++){
  759. printf("%d ",polje[i][j].enabled);
  760. }
  761. printf("\n");
  762. }
  763. Prim(polje,n,m);
  764. ispis(polje,n,m);
  765. for(i=0;i<n;i++){
  766. for(j=0;j<m;j++){
  767. printf("%d ",polje[i][j].enabled);
  768. }
  769. printf("\n");
  770. }
  771. int x1,y1,x2,y2;
  772. scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
  773. printf("%d",bfs(polje,x1,y1,x2,y2,n,m));*/
  774.  
  775. return 0;
  776. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement