🔒 Closed Help! naman po veteran sa programming

Status
Not open for further replies.

Jirachi2016

Established
Mga boss sana may makatulong sa akin diko alam kung paano toh
Topic po ay sa Hashing
Linear Probing Collision Resolution

#define LOAD_FACTOR 20
struct ListNode {
int key;
int data;
struct ListNode *next;
};
struct HashTableNode {
int bcount;
struct ListNode *next;
};
struct HashTable {
int tsize;
int count;
struct HashTableNode **Table;
};
struct HashTable *CreateHashTable(int size){
struct HashTable *h
h = (struct HashTable *)malloc(sizeof(struct HashTable));
if(!h)
return NULL;
h tsize = size/ LOAD_FACTOR;
h ount = 0;
h Table = (struct HashTableNode *)malloc(sizeof(struct HashTableNode *) h tsize);
if(! Table){
cout("Memory Error");
return NULL;

}
for(int i=0; i<h-size;i++){
h Table next = NULL;
h Table bcount = 0;
}
return h;
}
int HashSearch(struct HashTable *h, int data){
struct ListNode *temp;
temp = h Table[Hash(data, h tsize)] next;
while (temp){
if (temp-data == data)
return 1;
temp = temp next;
}
return 0;
}
int HashInsert(Struct HashTable *h, int data){
int index;
struct ListNode *temp, *newNode;
if(HashSearch(h,data))
return 0;
index = Hash(data, h- tsize);
newNode = (struct ListNode *)malloc(sizeof(struct ListNode));
if(!newNode){
printf("Out of Space");
return -1;
}
newNode key = index;
newNode data = data;
newNode next = h Table[index] next;

}
h Table[index] next = newNode;
h Table[index] bcount++;
h count++;
if(h count / h size > LOAD_FACTOR)
Rehash(h);
return 1;
}
int HashDelete(Struct HashTable *h, int data){
int index;
struct ListNode *temp, *prev;
index = Hash(data, h tsize);
for(temp = h Table[index] next, prev = NULL; temp,temp = temp next){
if(temp data == data){
if(prev!=NULL)
prev next = temp next
free(temp);
h Table[index] bcount--;
h count--;
return 1;
}
}
return 0;
}
void Rehash(Struct HashTable *h){
int oldsize,i,index;
struct ListNode *p, *temp, *temp2;
struct HashTableNode **oldTable;
oldsize = h tsize;
oldtableNode **oldTable;
h tsize = h tsize * 2;
h Table = (struct HashTableNode **)malloc(h tsize * sizeof(struct HashTableNode *));
if(!h Table){
printf("Allocation Failed");
return;
}
for(i = 0; i < oldsize; i++){
index = Hash(temp; temp data, h tsize);
temp2 = temp;temp = temp next;
temp2 next = h Table[index] next;
h TAble[index] next = temp2;
}
}
 
i think para magets ito you need to have an advance knowledge in C language specially sa data structures and pointers, some hashing algorithms and a good debugger (to trace this), but to trace this, you need to have an entrypoint(parang walang entrypoint) so di makita paano ginamit ung mga functions na to, pero from the looks of it, parang parsing functions ng isang hash algorithm. for context, saan mo kelangan to?
 
Status
Not open for further replies.

About this Thread

  • 5
    Replies
  • 431
    Views
  • 6
    Participants
Last reply from:
nestyplus

Online now

Members online
925
Guests online
791
Total visitors
1,716

Forum statistics

Threads
2,276,317
Posts
28,969,104
Members
1,231,208
Latest member
phcFREDOMA
Back
Top