CS 2005 Techniques of Programming
WPI, B Term 1994
Craig E. Wills
Exam 2 (100 pts)
Given: Friday, Dec 2, 1994
NAME: LAB TIME:
1.5em 1.5em
This is a closed book (and notes) examination. Answer all questions on the exam itself. Take the number of points assigned to each problem and the amount of space provided for your answer as a measure of the length and difficulty of the expected solution. The exam totals 100 points.
SCORE:
####### # # # #> # # # # ## ## # #< # #######
int Hash(int value) { return(value%10); }
Show where each of the following integers are inserted in the hash table of 10 entries if this hash function is used with linear probing (closed hashing) to resolve collisions. Be sure and indicate the hash value for each value.
1110 1129 3145 2309 2175
struct nodetag { /* node definition */ int item; struct nodetag *pNodeNext; }; struct queue { /* queue definition */ struct nodetag *pNodeFront; /* front of the queue list */ struct nodetag *pNodeRear; /* rear of the queue list */ };
Write the code for the function AddQueue, which is passed a pointer to the queue structure (already initialized and possibly containing values) and an integer to add to the list. The function MakeNode() allocates space for the node, filling in the item field with the value passed and setting the pNodeNext field to NULL.
int AddQueue(int value, struct queue *pqueue) { struct nodetag *pNode; if ((pNode = MakeNode(item)) == NULL) return(-1); /* error */ else { /* your code goes here */ } return(0); /* successfully added */ }
int SumValue(struct queue *pqueue) { /* your code goes here */ }
struct nodetag { int item; struct nodetag *pNodeNext; }; struct nodetag *pNodeHead; /* head of list */