deleteHa.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /***********************************************************
  2. *
  3. * deleteHa.c (for spread)
  4. * This routine is to delete a cell in a heap.
  5. * It 1) searches the cell backward and sequentially from
  6. * the heap (if not found, returns a error message),
  7. * 2) overwrites that cell and calls fixH routine to
  8. * restore a heap order.
  9. *
  10. ************************************************************/
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include "costHa.h"
  14. #include "local_proto.h"
  15. void
  16. deleteHa(float old_min_cost, int row, int col,
  17. struct costHa *heap, long *heap_len)
  18. {
  19. /* struct costHa *fixHa(); */
  20. long i;
  21. if (*heap_len < 1) {
  22. printf("programming ERROR: can't delete a cell from an ampty list");
  23. exit(1);
  24. }
  25. /* search the old_cell from the heap */
  26. for (i = 0; i <= *heap_len; i++) {
  27. if (heap[i].min_cost == old_min_cost &&
  28. heap[i].row == row && heap[i].col == col)
  29. break;
  30. }
  31. if (i == 0) {
  32. printf("programming ERROR: can't find the old_cell from the list");
  33. exit(1);
  34. }
  35. /* overwrite that cell, fix the heap */
  36. fixHa(i, heap, *heap_len);
  37. *heap_len = *heap_len - 1;
  38. return;
  39. }