| | |
Hashing- Linklist Chaining
![]() |
•
•
Join Date: Dec 2007
Posts: 17
Reputation:
Solved Threads: 1
Added just to help other....
c Syntax (Toggle Plain Text)
#include<stdio.h> #include<conio.h> #include<stdlib.h> void createHashTable(void); void getData(void); void formatting(void); int insertData(int); int collision_OpenHashing(struct hashOpen*& ,int); int generateKey(int); void DispData(void); void DispHash(void); #define dataSize 15 #define empty -1 #define fail 0 #define success 1 struct hashOpen{ int item; struct hashOpen *next; }*head, hashTable[10]; int dataArray[dataSize]; struct hashOpen* cur; int count, status; int filledSpaces = 0; float loadFactor = 0; void main(void) { clrscr(); formatting(); getData(); createHashTable(); count = 0; do { DispData(); DispHash(); printf("\ncount=%d", count); status = insertData(dataArray[count]); count++; } while (count <= dataSize); printf("\n\n-------------Programming Successfully Completed-------------"); getch(); } void createHashTable(void) { int i; /******** Initialize HashTable ************************/ for( i = 0; i <= 9; i++) { hashTable[i].item = empty; hashTable[i].next = NULL; } } void getData(void) { int i; randomize(); for(i =0; i < dataSize; i++) dataArray[i] = random(1)+2; } void DispData(void) { int i; printf("\nData[]={"); for(i =0; i < dataSize; i++) printf("%d,", dataArray[i]); printf("\b}"); } void DispHash(void) { int count; printf("\nHash Table content = ["); for(count = 0; count < 9 ; count++) { printf("%d, ", hashTable[count].item); cur++; } printf("\b\b]"); } void formatting(void) { int i; printf("\n"); for(i =0; i<=79 ; i++) printf("*"); printf("\n......... Prgogram title\t\t# Hash Table"); printf("\n......... Created by\t\t # Romasa Qasim"); printf("\n......... Description\t\t # Creation of Hash Table, generation of,"); printf("\t\t\t\t\t Key, Insertion, Searching and Deletion"); printf("\t\t\t\t\t of data in the Hash Table\n"); for( i =0; i<=79 ; i++) printf("*"); } int insertData(int data) { int hashIndex; hashIndex = generateKey(data); if( hashTable[hashIndex].item == empty) { hashTable[hashIndex].item = data; return(success); } else return(collision_OpenHashing(hashTable[hashIndex].next, data)); } int collision_OpenHashing(struct hashOpen *&pNode, int data) { if(pNode == NULL) { head = (struct hashOpen*)malloc(sizeof(struct hashOpen)); head->item = data; head->next = NULL; pNode = head; } else collision_OpenHashing(pNode->next, data); } int generateKey(int data) { int key; key = data % 10; return(key); }
Last edited by Narue; Dec 12th, 2007 at 3:21 pm. Reason: Added code tags
•
•
Join Date: Apr 2007
Posts: 18
Reputation:
Solved Threads: 0
hey friends just come across this program and found it very fruitfull....but would be more so happy if some one coould explain what tasks are we trying to achieve....or in short how would i be able to explain this program to some one ...so if someone with good knowledge about this topic can explain to me what
void createHashTable(void);
void getData(void);
void formatting(void);
int insertData(int);
int collision_OpenHashing(struct hashOpen*& ,int);
int generateKey(int);
void DispData(void);
void DispHash(void)
what the following functions are doing in this program
please some one who can guide me through various stages of this program so i can grasp it properly and be able to explain and perform it !!
regards,
Rash
void createHashTable(void);
void getData(void);
void formatting(void);
int insertData(int);
int collision_OpenHashing(struct hashOpen*& ,int);
int generateKey(int);
void DispData(void);
void DispHash(void)
what the following functions are doing in this program
please some one who can guide me through various stages of this program so i can grasp it properly and be able to explain and perform it !!
regards,
Rash
•
•
Join Date: Dec 2007
Posts: 17
Reputation:
Solved Threads: 1
void createHashTable(void);
This function creates a hash table in which the data items are to be inserted in sorted form for better searching
void getData(void);
This function collects data from user to be inserted in the hash table
void formatting(void);
This function is just to beautify the output of the program
int insertData(int);
This function ineserts the data in the hash table
int collision_OpenHashing(struct hashOpen*& ,int);
This function works when there is a collision occured in the table e.g if two data items with same key are to be inserted in the hash table then there must be a collision, both data items are the candidate for the same cell of hash table. To remove this collision This function acts as a collision resolver between that two data items.
int generateKey(int);
This function generates the key for the data items to be inserted with the help of a formula
void DispData(void);
This function displays the data to the end user
void DispHash(void)
This function displays the state of hash table after each entry
----------------------------------------------------------------------------------------------------
this is the introduction of all the funstion's performance, if you need description of coding then do acknowledge me.
Regards,
Romasa
This function creates a hash table in which the data items are to be inserted in sorted form for better searching
void getData(void);
This function collects data from user to be inserted in the hash table
void formatting(void);
This function is just to beautify the output of the program
int insertData(int);
This function ineserts the data in the hash table
int collision_OpenHashing(struct hashOpen*& ,int);
This function works when there is a collision occured in the table e.g if two data items with same key are to be inserted in the hash table then there must be a collision, both data items are the candidate for the same cell of hash table. To remove this collision This function acts as a collision resolver between that two data items.
int generateKey(int);
This function generates the key for the data items to be inserted with the help of a formula
void DispData(void);
This function displays the data to the end user
void DispHash(void)
This function displays the state of hash table after each entry
----------------------------------------------------------------------------------------------------
this is the introduction of all the funstion's performance, if you need description of coding then do acknowledge me.
Regards,
Romasa
![]() |
Similar Threads
- Hashing guidance (C)
Other Threads in the C Forum
- Previous Thread: Fgets,gets in a function?
- Next Thread: C working with string problem
| Thread Tools | Search this Thread |
#include * adobe ansi array asterisks bash binarysearch centimeter changingto char character cm convert copyimagefile cprogramme creafecopyofanytypeoffileinc database dynamic execv feet fgets file floatingpointvalidation fork function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux hacking histogram ide inches include incrementoperators infiniteloop input interest intmain() iso kernel keyboard kilometer license linked linkedlist linux list locate looping lowest matrix meter microsoft number oddnumber opendocumentformat openwebfoundation owf pattern pdf performance pointer posix power probleminc process program programming radix recursion recv recvblocked research reversing scripting segmentationfault sequential single socket socketprograming socketprogramming standard strchr string suggestions systemcall test threads turboc unix urboc user variable voidmain() wab whythiscodecausesegmentationfault windowsapi





