Advertisement
Guest User

Untitled

a guest
Dec 2nd, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. void insert_edge(graphT *g, int x, int y, int w)
  2. {
  3. edgenodeT *pe, *current, *prev;
  4. pe = malloc(sizeof(edgenodeT)); // check if NULL
  5. pe->weight = w;
  6. pe->y = y;
  7. pe->next = NULL;
  8. // YOU MUST MODIFY THIS FUNCTION SO IT WILL KEEP LINK LIST SORTED
  9. // W.R.T. NEIGHBOR IDs.
  10. current = g->edges[x];
  11. if(current == NULL) {
  12. g->edges[x] = pe;
  13. } else {
  14. while(current) {
  15. if(current->y > pe->y) {
  16. if(prev == NULL) {
  17. g->edges[x] = pe;
  18. pe->next = current;
  19. } else {
  20. pe->next = current;
  21. prev->next = pe;
  22. }
  23. break;
  24. }
  25. if(current->next == NULL) {
  26. current->next = pe;
  27. pe->next = NULL;
  28. break;
  29. } else {
  30. prev = current;
  31. current = current->next;
  32. }
  33. }
  34. }
  35. g->degree[x]++;
  36. g->nedges++;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement