Guest User

Untitled

a guest
Jul 22nd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. List * zeroPredList;
  2. List * list;
  3. List retList;
  4. Int * count;
  5. int num_Nodes, index, value, pred, succ;
  6.  
  7. if (fscanf(idata, "%d", &num_Nodes) == EOF) {
  8. printf("Number of nodes is inaccessible.\n");
  9. return NULL;
  10. }
  11.  
  12. zeroPredList = makeList(sizeofInt(), copyInt, free);
  13. list = (List *)calloc(num_Nodes, sizeof(List));
  14.  
  15. index = 0;
  16. /* Make a list for each node for successor/predecessor upkeep */
  17. while (index < num_Nodes) {
  18. list[index] = makeList(sizeofInt(), copyInt, free);
  19. }
  20.  
  21. /* Pred count of succ is incremented and succ goes in pred list */
  22. while (fscanf(idata, "%d %d", &pred, &succ) != EOF) {
  23. count[succ]++;
  24. insertTail(list[pred], &succ);
  25. }
  26.  
  27. index = 0;
  28. /* Put items with no pred into zero-pred list */
  29. while (index < num_Nodes) {
  30. if (count[index] == 0) {
  31. insertTail(zeroPredList, &index);
  32. }
  33. index++;
  34. }
  35.  
  36. /* Remove item k from zero-pred list and output record. Traverse
  37. k successor list and decrement the count for each record found.
  38. If record j count is set to zero, then include j on the zero-pred
  39. list. Continue until zero-pred list is emtpy */
  40.  
  41. while (deleteTail(zeroPredList, &value)) {
  42.  
  43. /* Push zero-pred items onto the returned list */
  44. insertTail(retList, &value);
  45. Int temp;
  46. while (deleteTail(list[value], temp)) {
  47. count[valueInt(temp)]--;
  48. if (count[valueInt(temp)] == 0) {
  49. insertTail(zeroPredList, &temp);
  50. }
  51. }
  52. }
  53.  
  54.  
  55. return retList;
Add Comment
Please, Sign In to add comment