Guest User

Untitled

a guest
Jan 22nd, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "PriQ.h"
  4.  
  5. int main (int argc, char *argv[]){
  6. int n, i = 0;
  7. Edge temp;
  8. if(scanf("%d", &n)==1){
  9. Graph g = newGraph(n);
  10.  
  11. float *x = malloc(sizeof(*x)*n);
  12. int *v = malloc(sizeof(*v)*n);
  13. int *w = malloc(sizeof(*w)*n);
  14. if(x==NULL || v==NULL || w==NULL){
  15. fprintf(stderr, "main: out of memory\n");
  16. exit(EXIT_FAILURE);
  17. }
  18.  
  19. for(i=0; i<n; i++){
  20. x[i]=0;
  21. v[i]=0;
  22. w[i]=0;
  23. }
  24. i = 0;
  25. while(scanf("%d-%d:%f", &v[i], &w[i], &x[i])==3){
  26. temp = newE(v[i], w[i], x[i]);
  27. insertE(g, temp);
  28. i++;
  29. }
  30. showGraph(g);
  31.  
  32. //PRIORITY QUEUE STUFF
  33. PriQ pq = createPQ(n);
  34. for(i=0; i<n; i++){
  35. temp = newE(v[i], w[i], x[i]);
  36. insertPQ(pq, temp);
  37. }
  38. for(i=0; i<n; i++){
  39. temp = delMaxPQ(pq);
  40. showE(temp);
  41. }
  42. }
  43. return EXIT_SUCCESS;
  44. }
Add Comment
Please, Sign In to add comment