Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // HashingFunctions.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <string.h>
- typedef struct
- {
- char name[20];
- int facultyNumber;
- Student next;
- } Student;
- Student *students[1024];
- int _tmain(int argc, _TCHAR* argv[])
- {
- *students = (Student *)malloc(1024 * sizeof(Student *));
- Student newStudent;
- strcpy(newStudent.name,"Pesho");
- newStudent.facultyNumber = 2012123;
- if(search(newStudent.facultyNumber) != NULL)
- {
- printf("Found!");
- }
- else
- {
- printf("Not found!");
- }
- return 0;
- }
- Student * search(int facultyNumber)
- {
- int currentStudentPositionInArray = returnHashCode(facultyNumber);
- for(Student *current = students[currentStudentPositionInArray]; current!=NULL; current = current->next)
- {
- if(current ->facultyNumber == facultyNumber)
- {
- return current;
- }
- }
- return NULL;
- }
- int returnHashCode(int key)
- {
- int hash = (int)(key % 1024);
- return hash;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement