Thread: HashIndex

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    4

    HashIndex

    So i have to write this function that creates a node to hold a student record specified by siid(student_id), lastname, firstname and gpa. After creating the new node i have to insert it to the proper list in the hash table pointed by hashtable. The memory of the new node is dynamically allocated. my question is: Two students cannot have the same student_id , so if the inserted record has the same student_id with an existing record in the list my program should print to the standard output:

    insertion failed: student_id xxxxxx already exists

    where xxxxxx is the student_id valuemy second question: If the insertion of a record is successful it should print:
    .
    record xxxxx inserted

    this is what i have so far:



    void insertRecord(Student **hashtable, unsigned int sid, char *lastname, char *firstname, float gpa);
    {

    Student *p, *head;
    p=(student *) malloc(sizeof(student));

    int i;

    Student *s;/*node*/

    if (s==NULL)
    {
    s->student_id =sid;
    strcpy(s->firstname,firstname);/*copying first and lastname to s*/
    strcpy(s->lastname,lastname);
    s->gpa=gpa;
    hashtable[sid%M] = s;
    }

    else
    {/*s != NULL;*/
    s = s-> next;
    s->student_id=sid;

    }
    if (student_id = s)
    {
    printf("insertion failed: student_id %d already exists\n", sid);
    }
    printf("record %d inserted", sid);

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Also here:
    HashIndex

    Don't cross-post
    Use code tags
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hash Table
    By mrsirpoopsalot in forum C++ Programming
    Replies: 11
    Last Post: 11-14-2009, 09:10 PM