problem: a list represented using cursor based implementation contains all ACT, BSCS, BSICT, BSIT and BSMATH students. A dictionary is created implemented using open hashing for BSCS and BSIT students. Each grouping the dictionary is a list implemented using cursor based. given below is the definition of the LIST, Dictionary, Virtual heap.
#define maxCells 1000
#define maxGrp 10
typedef struct
{
char LN[16], FN[24],MI;
}nametype;
typedef struct studtype
{
unsigned long ID;
nametype name;
char course[8];
int yr;
}student;
typedef struct ctype
{
student stud;
int next;
}celltype;
typedef int LIST;/*LIST is implemented using cursor base*/
typedef struct
{
LIST Header; /*holds the index of the first element in each group*/
int StudCtr; /*holds the number of elements in each group*/
}Group;
typedef Group * Dictionary;
typedef struct
{
celltype heap[maxCells];
int AvailPtr;/*holds the index to the next available cell in the virtual heap*/
}*VirtualHeap;
problem 1:
write the code of function Hash. the function will return the remainder of when the total sum of all digits of the ID will be divided by maxGrp.
here's my answer:
int Hash(celltype x)
{
int sum;
unsigned long ID, i;
ID=x.stud.ID;
for(i=100000;i>0;i%=10)
{
sum += ID/i;
ID%=i;
}
return (sum%maxGrp);
}
my teacher said that the celltype in the parameter is wrong and also sum and i%=10 but he didn't explain why i tried to run it and yes he was right but i don't understand what is wrong so please explain why that is.