/*  Print the list

    param:  heap    pointer to the list
    pre:    the list is not empty
    post:   The tasks from the list are printed out in priority order.
			The tasks are not removed from the list.
*/
void printList(DynArr *heap)
{
    /* FIXME: Write this */
    struct DynArr *toPrint = createDynArr(sizeDynArr(heap));
    copyDynArr(heap, toPrint);
    int i, max = sizeDynArr(toPrint);
    sortHeap(toPrint);
    // call print_type() on each node
    for(i = 0; i < max; i++)
        print_type(getDynArr(toPrint, i));
        deleteList(toPrint);
}
Exemple #2
0
/*  Print the list

    param:  heap    pointer to the list
    pre:    the list is not empty
    post:   The tasks from the list are printed out in priority order.
			The tasks are not removed from the list.
*/
void printList(DynArr *heap)
{
  /* FIXME: Write this */

  // create a new copy of the heap to prevent removal
  DynArr *tmpHeap = createDynArr(sizeDynArr(heap));
  copyDynArr(heap, tmpHeap);
  
  while (sizeDynArr(tmpHeap) > 0)
    {
      // get first value of min priority
      TYPE min = getMinHeap(tmpHeap);
      print_type(min);
      removeMinHeap(tmpHeap); // remove min, to get next
    }

  freeDynArr(tmpHeap);
}
/*  Print the list

    param:  heap    pointer to the list
    pre:    the list is not empty
    post:   The tasks from the list are printed out in priority order.
			The tasks are not removed from the list.
*/
void printList(DynArr *heap)
{
    assert(sizeDynArr(heap) > 0);
    DynArr *tempList; // temp list for sorting
    Task *tempTask; // temp task pointer
    int i;

    tempList = malloc(sizeof(sizeDynArr(heap)));
    copyDynArr(heap, tempList);
    sortHeap(tempList);

    // iterate through sorted array and print tasks
    printf("\nYour list sorted by priority:\n");
    for(i = sizeDynArr(tempList) - 1; i >= 0; i--) {
        tempTask = getDynArr(tempList, i);
        printf("%d.\t%s\n", tempTask->priority, tempTask->description);
    }
    printf("\n");
}
Exemple #4
0
/*  Print the list
 
 param:  heap    pointer to the list
 pre:    the list is not empty
 post:   The tasks from the list are printed out in priority order.
 The tasks are not removed from the list.
 */
void printList(DynArr *heap)
{
    DynArr *temp;
    TaskP task;
    assert(sizeDynArr(heap) > 0);
    
    temp = createDynArr(sizeDynArr(heap));
    /* copy the main list to a temp list
     * so that tasks can be printed out and removed.
     */
    copyDynArr(heap, temp);
    while(sizeDynArr(temp) > 0)
    {
        /* get the task */
        task = getMinHeap(temp);
        /* print the task */
        printf("%d:  %s\n\n", task->priority, task->description);
        /* remove the task */
        removeMinHeap(temp);
    }
    /* free the temp list */
    deleteDynArr(temp);
}
Exemple #5
0
/*  Print the list in priority order.  This requires that either we sort it...or make a copy and pull
off the smallest element one at a time.  That's what we've done here.

    param:  heap    pointer to the list
    pre:    the list is not empty
    post:   The tasks from the list are printed out in priority order.
			The tasks are not removed from the list.
*/
void printList(DynArr *heap)
{
  DynArr *temp;
  TaskP task;
  assert(sizeDynArr(heap) > 0);

  temp = createDynArr(sizeDynArr(heap));
  /* copy the main list to a temp list
   * so that tasks can be printed out and removed.
   */
  copyDynArr(heap, temp);
  while(sizeDynArr(temp) > 0)
    {
      /* get the task */
      task = getMinHeap(temp);

      /* print the task */
      printf("%d:  %s\n\n", task->priority, task->description);
      /* remove the task , but let's not free up the memory it's pointing to since old Arr is using it!*/
      removeMinHeap(temp, compare);
    }
  /* free the temp list */
  deleteDynArr(temp);
}