a. array b. singly-linked list c. doubly-linked list d. queue e. stack
For each of the following questions choose the best answer from the above list. Sometimes it may seem as though two or more choices would be equally good. In those cases think about the operations that the data structures support and choose the data structure whose operations are best suited for the problem. You may have to use the same answer for more than one question:
struct node { struct node *next; struct node *prev; int value; }; struct node *my_node;
my_node = 0xa0 my_node->prev = 0x9c my_node->next = 0xb4 my_node->value = 6 my_node->next->next = 0xc8 my_node->next->value = 8
Draw the memory diagram for my_node and its successor node. In particular, label the boxes in the following diagram with the appropriate hexadecimal addresses and in each box either indicate the name of the field and the value stored at that memory location or leave the box blank if the contents at that memory location are unknown.
-------------------------------- | | | | -------------------------------- | | | | -------------------------------- | | | | -------------------------------- | | | | -------------------------------- | | | | -------------------------------- | | | | -------------------------------- | | | | -------------------------------- | | | | -------------------------------- | | | | -------------------------------- | | | | --------------------------------
int max_sum(int *array, int size, int *save_i, int *save_j) { int max = 0; int i, j; for (i = 0; i < size-1; i++) { for (j = i+1; j < size; j++) { if (array[j] > array[i]) { if ((array[j] + array[i]) > max) { max = array[j] + array[i]; *save_i = i; *save_j = j; } } } } return max; }
#define SIZE 10 int a[SIZE]; int max; int index1; int index2;
Write a line of code that will call max_sum and save the return result in max, the value of save_i in index1 and the value of save_j in index2.