الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

برنامج موسهل اذا تعرف تبرمج بلييز ساعدني

مغلق
بدأه AIZ في 20 ديسمبر 2006 · 13 رد · 956 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

بسم الله الرحمن الرحيم

قوه شلونكم شخباركم

انا عندي مشكله و ابي احد يساعدني بفكرة حل انا مابي برنامج كامل لان ادري محد عنده وقت او له خلق

البرنامج شوي معقد و فيه تحدي من الدكتور لنا !!! :"(

البرنامج عباره عن نظام لوزارة الصحه احنا سوينا منه نسختين نسخه باللنك لست و الثانيه بال binary search trees و كان كل شي اوكيك

بس الحيين الدكتور يبي البرنامج بال hash !!! انا اول مره اخذ الهاش و ماعرفله كلش كلش

بكتب نص السؤال و محاولاتي فيه و نسخه البرنامج اللي باللنك لست !! انا مابي حل و السلام انا اعرف ابرمج بس مشكلتي ان الهاش محد علمني علييه

repeat programming assigment-2 by using hash -table instead of every linked list

hence ,you will have atotal of 6 different hash tables ,separate hash table for

clinic,doctor,nurses,staff members ,service companies, and patient

-use 4 different hash tfunctions of your choice

-use linear proping collision resolution for clinic hash table

-use chaining collisin resolution for doctors hashtable

-use chaininh with BST collision resolution for the patient hash table

-use dynamic hashing for the nurses hash table

-use rehashing collision resolution for staff members hash table

-use quadratic probing collision resolution for service companies hash table>

و يبينا نحلل time & space complexity لل برامج الثلاثه الترييز و الهاش و اللنك لست !!!!

هذا السؤال وانا اول مره اسمع بالهاش !!!!!!

:::::::::::::::::::::::::::::::::::::::::::::::::::::هذي محاولاتي الفاشله

#include<stdio.h>

#include<string.h>

#define MAX_CHAR 10 /*max number of characters in an identifier*/

#define TABLE_SIZE 13 /*max table size=prime number*/

#define IS_FULL(ptr) (!(ptr))

typedef struct{

char key[MAX_CHAR];/*other fields*/

}element;

element hash_table[TABLE_SIZE];

typedef struct list *list_pointer;

typedef struct list{

element item;

list_pointer link;

};

list_pointer hash_table[TABLE_SIZE];

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void init_table(element ht[])

{

int i;

for(i = 0; i < TABLE_SIZE; i++)

ht.key[0] = NULL;

}

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

int transform(char *key)

{/*simple additive approach to create a natural number that

is within the integer range */

int number =0;

while(*key)

number += *key++;

return number;

}

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

int hash(char *key)

{/* transform key to a natrual number , and return this

result modulus the table size*/

return (transform(key) % TABLE_SIZE);

}

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void linear_insert(element item, element ht[])

{/*insert the key into the table using the linear proping

teachique, exit the function if the table is full*/

int i, hash_value;

hash_value = hash(item.key);

i= hash_value;

while(strlen(ht.key)){

if(!strcmp(ht.key,item.key)){

printf("\n:::DUPLICATE ENTRY:::\n");

exit(1);

}

i=(i+1)%TABLE_SIZE;

if(i==hash_value){

printf("\n:::TABLE IS FULL:::\n");

exit(1);

}

}//while

ht=item;

}

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void chain_insert(element item,list_pointer ht[])

{/* insert the key into the table using chaining*/

list_pointer ptr,trail,lead;

int hash_value ;

hash_value= hash(item.key);

trail=NULL;

lead=ht[hash_value];

for(; lead;trial=lead,lead=lead->link)

if(!strcmp(lead->item.key,item.key)){

printf("\n:::THE KEY IS IN THE TABLE:::\n");

exit(1);

}

ptr=(list_pointer)malloc(sizeof(list));

if(IS_FULL(ptr)){

printf("\n:::NO MEMORY:::\n");

exit(1);

}

ptr->item=item;

ptr->link=NULL;

if(trial)

trial->link=ptr;

else

ht[hash_value]=ptr;

}

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

هذا برنامج شغال باللنك لست انا خليته اهنيه عشان الملف كبير حيل و ردو علي بلييز حتى لو بفكرت حل !!!!!بليييييييييييييييييييييييييييييييييييييز

::::::::::::::::::::::::::::::

/*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*

*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*/

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

typedef struct patient{

char fn[10];

char ln[10];

char cid[12];

char app[15];

FILE *cond;

struct patient *next;

}patient;

typedef struct ser{

char cn[10];

char add[10];

char tel[7];

char wh[10];

struct ser *next;

}ser;

typedef struct staff {

char fn[10];

char ln[10];

char add[10];

char tel[7];

char wh[10];

struct staff *next;

}staff;

typedef struct nr {

char fn[10];

char ln[10];

char add[10];

char tel[7];

char wh[10];

struct nr *next;

}nr;

typedef struct dr{

char fn[10];

char ln[10];

char add[10];

char tel[7];

char wh[10];

struct patient *ptr;

struct dr *next;

}dr ;

typedef struct clinic{

char clinic_name[10];

struct dr *drptr;

struct nr *nrptr;

struct staff *stafptr;

struct ser *serptr;

struct clinic *next;

}clinic ;

typedef struct {

char hos[10];

struct clinic *ptr;

}node;

node arr[10];

char name[10], ln[10],fn[10];

int count=0;

//************************************************************************************************

// SEARCHING FUNCTIONS

//************************************************************************************************

int search_hosp (char name [10])

{

int i,j=-1;

for(i=0;i<count;i++)

if((strcmp(arr.hos,name))==0)

{

j=i;

break;

}

return j;

}// end of func

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

clinic * search_clinic (int i,char name[10])

{

clinic *p;

p=arr.ptr;

while(p != NULL)

{

if(strcmp(p->clinic_name,name)==0)

break;

else

p=p->next;

}

return p;

}//end of func

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

dr * search_doc(clinic *p,char name[10],char ln[10])

{

dr * doc ;

doc =p->drptr;

while(doc!=NULL)

{

if(strcmp(doc->fn,name)==0&&strcmp(doc->ln,ln)==0)

return doc;

else

doc=doc->next;

}

return doc;

}

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

nr * search_nurs (clinic *p,char name[10],char ln[10])

{

nr * nur ;

nur =p->nrptr;

while(nur!=NULL)

{

if(strcmp(nur->fn,name)==0&&strcmp(nur->ln,ln)==0)

break;

else

nur=nur->next;

}

return nur;

}//end

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

staff * search_staff (clinic *p,char name[10],char ln[10])

{

staff * staf ;

staf =p->stafptr;

while(staf!=NULL)

{

if(strcmp(staf->fn,name)==0&&strcmp(staf->ln,ln)==0)

return staf;

else

staf=staf->next;

}

return NULL;

}//end

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

ser * search_serv (clinic *p,char name[10])

{

ser * serv ;

serv =p->serptr;

while(serv!=NULL)

{

if(strcmp(serv->cn,name)==0)

break;

else

serv=serv->next;

}

return serv;

}//end

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

patient * search_patient(dr *doc, char name[10], char ln[10])

{

patient *pati;

pati=doc->ptr;

while(pati!=NULL)

{

if(strcmp(pati->fn,name)==0 && strcmp(pati->ln,ln)==0)

break;

else

pati=pati->next;

}

return pati;

}

//**************************************************************************************************

// INSERTION FUNCTIONS

//**************************************************************************************************

void insert_hosp()

{

int i;

char ch;

if(count>=10)

printf(":::ARRAY OF HOSPITAL IS FULL:::\n");

else{

printf("\n::: Enter the name of the hospitals (10 max) ::: \n");

while(count<10 && ch!='n')

{

scanf("%s",name);

i=search_hosp(name);

if(i< 0)

{

strcpy(arr[count].hos,name);

count++;

printf("Do u want to insert anther hospital (y or n) :");

scanf(" %c",&ch);

}

else

{

printf(":::THE HOSPITAL IS ALREADY EXIST:::\n");

break;

}

}}

}

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void insert_clinic()

{

int i;

clinic *newcli,*p;

printf("Enter hospital to add new clinic to it\n");

scanf("%s",name);

i=search_hosp(name);

if(i>=0)

{

printf("Enter the name of the clinic:");

scanf("%s",name);

p=search_clinic(i,name);

if(p== NULL)

{

newcli=(clinic *)malloc(sizeof(clinic));

strcpy(newcli->clinic_name,name);

newcli->drptr=NULL;

newcli->nrptr=NULL;

newcli->serptr=NULL;

newcli->stafptr=NULL;

newcli->next=NULL;

if(arr.ptr == NULL)

{

arr.ptr=newcli;

}//if

else

{

newcli->next=arr.ptr;

arr.ptr=newcli;

}//else

}

else

printf(":::CLINIC IS ALRADY EXIST:::\n");

}

else

printf("\n:::HOSPITAL NOT FOUND:::\n");

}

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void insert_doc()

{

int i;

dr *newdr,*doc;

clinic *p;

printf("Enter hospital to add a doctor in \n");

scanf("%s",name);

i=search_hosp(name);

if(i>=0)

{

printf("Enter clinic to add doctor in \n");

scanf("%s",name);

p=search_clinic(i,name);

if(p==NULL)

printf("\n:::CLINIC NOT FOUND:::\n");

else if(p != NULL)

{

printf("Please enter the doctor's first name:");

scanf("%s",name);

printf("Please enter the doctor's last name :");

scanf("%s",ln);

doc=search_doc(p,name,ln);

if(doc!=NULL)

printf(":::DOCTOR ALREADY EXIST:::\n");

else{

newdr=(dr *)malloc(sizeof(dr));

strcpy(newdr->fn,name);

strcpy(newdr->ln,ln);

printf("Please enter the doctor's address :");

scanf("%s",name);

strcpy(newdr->add,name);

printf("Please enter the doctor's tel. number :");

scanf("%s",name);

strcpy(newdr->tel,name);

printf("Please enter the doctor's working hours :");

scanf("%s",name);

strcpy(newdr->wh,name);

newdr->next=NULL;

newdr->ptr=NULL;

}

}//elseif

if(p->drptr==NULL)

p->drptr=newdr;

else

{

newdr->next=p->drptr;

p->drptr=newdr;

}

}//if

else printf(":::HOSPITAL NOT FOUND:::\n");

}// end

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void insert_nurs()

{

int i;

nr *newnr,*nur;

clinic *p;

printf("Enter hospital to add new nurs to it\n");

scanf("%s",name);

i= search_hosp(name);

if(i>=0)

{

printf("Enter clinic to add a nurs in \n");

scanf("%s",name);

p=search_clinic(i,name);

if(p==NULL)

printf("Clinic not found\n");

else if(p != NULL)

{

printf("Please enter the nurs's first name:");

scanf("%s",name);

printf("Please enter the nurs's last name :");

scanf("%s",ln);

nur=search_nurs(p,name,ln);

if(nur!=NULL)

printf(":::NURSE IS ALREADY EXIST:::\n");

else{

newnr=(nr *)malloc(sizeof(nr));

strcpy(newnr->fn,name);

strcpy(newnr->ln,ln);

printf("Please enter the nurs's address :");

scanf("%s",name);

strcpy(newnr->add,name);

printf("Please enter the nurs's tel. number :");

scanf("%s",name);

strcpy(newnr->tel,name);

printf("Please enter the nurs's working hours :");

scanf("%s",name);

strcpy(newnr->wh,name);

newnr->next=NULL;

}

}//else if

if(p->nrptr==NULL)

p->nrptr=newnr;

else

{

newnr->next=p->nrptr;

p->nrptr=newnr;

}

}//if

else printf(":::HOSPITAL NOT FOUND:::\n");

}// end

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void insert_staff()

{

int i;

staff *newstaf,*staf;

clinic *p;

printf("Enter hospital to add new staff member to it\n");

scanf("%s",name);

i= search_hosp(name);

if(i>=0)

{

printf("Enter clinic to add a staff membr in \n");

scanf("%s",name);

p=search_clinic(i,name);

if(p==NULL)

printf("Clinic not found\n");

else if(p != NULL)

{

printf("Please enter the staff member's first name:");

scanf("%s",name);

printf("Please enter the staff member's last name :");

scanf("%s",ln);

staf=search_staff(p,name,ln);

if(staf!=NULL)

printf(":::STAFF MEMBER IS ALREADY EXIST:::\n");

else{

newstaf=(staff *)malloc(sizeof(staff));

strcpy(newstaf->fn,name);

strcpy(newstaf->ln,ln);

printf("Please enter the staff member's address :");

scanf("%s",name);

strcpy(newstaf->add,name);

printf("Please enter the staff member's tel. number :");

scanf("%s",name);

strcpy(newstaf->tel,name);

printf("Please enter the staff member's working hours :");

scanf("%s",name);

strcpy(newstaf->wh,name);

newstaf->next=NULL;

}

}//else if

if(p->stafptr==NULL)

p->stafptr=newstaf;

else

{

newstaf->next=p->stafptr;

p->stafptr=newstaf;

}

}//if

else printf(":::HOSPITAL NOT FOUND:::\n");

}// end

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void insert_ser()

{

int i;

ser *newser,*serv;

clinic *p;

printf("Enter hospital to add new service company to it\n");

scanf("%s",name);

i= search_hosp(name);

if(i>=0)

{

printf("Enter clinic to add a service company in \n");

scanf("%s",name);

p=search_clinic(i,name);

if(p==NULL)

printf(":::CLINIC NOT FOUND:::\n");

else if(p != NULL)

{

printf("Please enter the name of the company:");

scanf("%s",name);

serv=search_serv(p,name);

if(serv!=NULL)

printf(":::SERVICE COMPANY IS ALREADY EXIST:::\n");

else

{

newser=(ser *)malloc(sizeof(ser));

strcpy(newser->cn,name);

printf("Please enter the service company's address :");

scanf("%s",name);

strcpy(newser->add,name);

printf("Please enter the service company's tel. number :");

scanf("%s",name);

strcpy(newser->tel,name);

printf("Please enter the serice company's working hours :");

scanf("%s",name);

strcpy(newser->wh,name);

newser->next=NULL;

}

}//else if

if(p->serptr==NULL)

p->serptr=newser;

else

{

newser->next=p->serptr;

p->serptr=newser;

}

}//if

else printf(":::HOSPITAL NOT FOUND:::\n");

}// end

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void insert_patient ()

{

clinic *p;

dr *doc;

patient *pat;

int i;

char fname[10],lname[10],date[10],word[100]="nothing";//word to copy in the file word by word

FILE *cond;

printf("In which hospital u want to add patient \n");

scanf("%s",name);

i=search_hosp(name);

if(i>=0)

{

printf("In which clinic do u want to add the patient\n");

scanf("%s",name);

p=search_clinic(i,name);

if(p != NULL)

{

printf("To which doctor u want to add the patient(first&last name)\n");

scanf("%s %s",name,ln);

doc=search_doc(p,name,ln);

if(doc != NULL)

{

printf("Enter the patient's first name\n");

scanf("%s",fname);

printf("Enter the patient's last name\n");

scanf("%s",lname);

pat=search_patient(doc,fname,lname);

if(pat==NULL)

{

pat=(patient *)malloc(sizeof(patient));

strcpy(pat->fn,fname);

strcpy(pat->ln,lname);

printf("Enter the patient's civil id :");

scanf("%s",name);

strcpy(pat->cid,name);

printf("Enter the next appointment(date) :");

scanf("%s",date);

strcpy(pat->app,date);

strcat(fname," ");

strcat(fname,lname);

strcat(fname,".txt");

if(!(cond=fopen(fname,"a+")))

printf(":::PATIENT'S CONDITION FILE NOT FOUND:::");

else{

fprintf(cond,"DATE:");

fprintf(cond,"%s",date);

fprintf(cond,"\n");

printf("Enter the medication of the patient:");

fprintf(cond,"The medication:");

gets(name);

gets(word);

fprintf(cond,"%s",word);

fprintf(cond,"\n");

printf("Enter condition of the patient\n");

gets(word);

fprintf(cond,"The condition:");

fprintf(cond,"%s ",word);

fprintf(cond,"\n****************************************************\n");

fclose(cond);

}//else

pat->next=NULL;

if(doc->ptr==NULL)

doc->ptr=pat;

else

{

pat->next=doc->ptr;

doc->ptr=pat;

}//else

}//if

else

printf(":::PATIENT IS ALREADY EXIST:::\n");

}

else

printf(":::DOTOR NOT FOUND:::\n");

}

else

printf(":::CLINIC NOT FOUND:::\n");

}//if

else printf(":::HOSPITAL NOT FOUND:::\n");

}// end

//******************************************************************************

// DELETION FUNCTIONS //

//******************************************************************************

void delete_hosp()

{

int i,j;

printf("Enter the hospital that u want to delete it :");

scanf("%s",name);

i=search_hosp(name);

if(i>=0)

{

for(j=i ;j<=10 &&(strcmp(arr[j].hos,"nothing")!=0) ;j++)

arr[j]=arr[j+1]; //shifting the array

count--;

}

else printf(":::HOSPITAL NOT FOUND:::\n");

}//end

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void delete_clinic()

{

int i;

clinic *p,*prev;

printf("Enter hospital to delete a clinic from it\n");

scanf("%s",name);

i=search_hosp(name);

if(i>=0)

{

printf("Enter clinic to delete it\n");

scanf("%s",name);

p=search_clinic(i,name);

if(p!=NULL)

{

prev=arr.ptr;

while(prev !=NULL)

{

if(prev->next==p)

{

prev->next=prev->next;

p->next=NULL;

free(p);

}

else

prev=prev->next;

}//while*/

}//if

else

printf(":::CLINIC NOT FOUND:::\n");

}

else

printf(":::HOSPITAL NOT FOND:::\n");

}

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void delete_doc()

{

int i;

dr *doc,*prev;

clinic *p;

printf("Enter hospital to delete a doctor from it\n");

scanf("%s",name);

i=search_hosp(name);

if(i>=0)

{

printf("Enter clinic to delete a doctor from it\n");

scanf("%s",name);

p=search_clinic(i,name);

if(p!=NULL)

{

printf("Enter doctor's first name to delete him/her \n");

scanf("%s",name);

printf("Enter doctor's last name to delete him/her \n");

scanf("%s",ln);

doc=search_doc(p,name,ln);

if(doc!=NULL)

{

prev =p->drptr;

while(prev !=NULL)

{

if(prev->next==doc)

{

prev=prev->next;

doc->next=NULL;

free(doc);

}

else

prev=prev->next;

}//while

}//if(doc!=NULL)

else

printf(":::DOCTOR NOT FOUND:::\n");

}//if(p!=NULL)

else

printf(":::CLINIC NOT FOUND:::\n");

}//if(i>=0)

else

printf(":::HOSPITAL NOT FOUND:::\n");

}// end

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void delete_nurs()

{

int i;

nr *nur,*prev;

clinic *p;

printf("Enter hospital to delete a nurse from it\n");

scanf("%s",name);

i=search_hosp(name);

if(i>=0)

{

printf("Enter clinic to delete a nurse from it\n");

scanf("%s",name);

p=search_clinic(i,name);

prev =p->nrptr;

if(p!=NULL)

{

printf("Enter nurse's first name to delete her/his \n");

scanf("%s",name);

printf("Enter nurse's last name to delete him/her \n");

scanf("%s",ln);

nur = search_nurs(p,name,ln);

if(nur!=NULL)

{

while(prev !=NULL)

{

if(prev->next==nur)

{

prev=prev->next;

nur->next=NULL;

free(nur);

}

else

prev=prev->next;

}//while

}//if(nur!=NULL)

else

printf(":::NURSE NOT FOUND:::\n");

}//if(p!=NULL)

else

printf(":::CLINIC NOT FOUND:::\n");

}//if(i>=0)

else

printf(":::HOSPITAL NOT FOUND:::\n");

}// end

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void delete_staf()

{

int i;

staff *staf,*prev;

clinic *p;

printf("Enter hospital to delete a staff member from it\n");

scanf("%s",name);

i=search_hosp(name);

if(i>=0)

{

printf("Enter clinic to delete a staff member from it\n");

scanf("%s",name);

p=search_clinic(i,name);

prev =p->stafptr;

if(p!=NULL)

{

printf("Enter staff member's first name to delete him/her\n");

scanf("%s",name);

printf("Enter staff member's last name to delete him/her\n");

scanf("%s",ln);

staf = search_staff(p,name,ln);

if(staf!=NULL)

{

while(prev !=NULL)

{

if(prev->next==staf)

{

prev=prev->next;

staf->next=NULL;

free(staf);

}

else

prev=prev->next;

}//while

}//if(staf!=NULL)

else

printf(":::STAFF MEMBER NOT FOUND:::\n");

}//if(p!=NULL)

else

printf("Clinic not found\n");

}//if(i>=0)

else

printf(":::HOSPITAL NOT FOUND:::\n");

}// end

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void delete_ser()

{

int i;

ser *serv,*prev;

clinic *p;

printf("Enter hospital to delete service company from it\n");

scanf("%s",name);

i=search_hosp(name);

if(i>=0)

{

printf("Enter clinic to delete service company from it\n");

scanf("%s",name);

p=search_clinic(i,name);

prev =p->serptr;

if(p!=NULL)

{

printf("Enter service company's name to delete it \n");

scanf("%s",name);

serv=search_serv(p,name);

if(serv!=NULL)

{

while(prev !=NULL)

{

if(prev->next==serv)

{

prev=prev->next;

serv->next=NULL;

free(serv);

}

else

prev=prev->next;

}//while

}//if(serv!=NULL)

else

printf(":::SERVICE COMPANY NOT FOUND:::\n");

}//if(p!=NULL)

else

printf(":::CLINIC NOT FOUND:::\n");

}//if(i>=0)

else

printf(":::HOSPITAL NOT FOUND:::\n");

}// end

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void delete_patient()

{

int i;

patient *pat,*prev;

dr *doc;

clinic *p;

printf("Enter hospital to delete a patient from it\n");

scanf("%s",name);

i=search_hosp(name);

if(i>=0)

{

printf("Enter clinic to delete a patient from it\n");

scanf("%s",name);

p=search_clinic(i,name);

if(p!=NULL)

{

printf("Enter the doctor's first name to delete one of his/her patients \n");

scanf("%s",name);

printf("Enter the doctor's last name to delete one of him/her patients \n");

scanf("%s",ln);

doc = search_doc(p,name,ln);

prev=doc->ptr;

if(doc !=NULL)

{

printf("Enter paitent's first name to delete him/her\n");

scanf("%s",name);

printf("Enter patient's last name\n");

scanf("%s",ln);

pat=search_patient(doc,name,ln);

if(pat!=NULL)

{

while(prev !=NULL)

{

if(prev->next==pat)

{

prev=prev->next;

pat->next=NULL;

free(pat);

}

else

prev=prev->next;

}//while

}//if(pat!=NULL)

else

printf(":::PATIENT NOT FOUND:::\n");

}//if(p!=NULL)

else

printf(":::DOCTOR NOT FOUND:::\n");

}

else

printf(":::CLINIC NOT FOUND:::\n");

}//if(i>=0)

else

printf(":::HOSPITAL NOT FOUND:::\n");

}// end

//******************************************************************************

// PRINTING FUNCTIONS //

//******************************************************************************

void print_hospital()

{

char ch ;

int i;

clinic *p;

do{

printf("1 > Show all hospitals\n");

printf("2 > Show all clinics in a given hospital\n");

printf("E > Exit\n");

printf("You'r choice :");

scanf(" %c",&ch);

if(ch=='1')

{

if(count<=0)

printf(":::THERE ARE NO STORED HOSPITALS:::\n");

else{

printf("The stored hospital:\n");

for(i=0; i<count ;i++)

printf("%s\n",arr.hos);

}

}

else if(ch=='2')

{

printf("Enter the name of the hospital\n");

scanf("%s",name);

i=search_hosp(name);

if(i>=0)

{

p=arr.ptr;

if(p == NULL)

printf(":::THERE ARE NO STORED HOSPITALS:::\n");

else{

printf("The stored clinic:\n");

while(p !=NULL)

{

printf("%s\n",p->clinic_name);

p=p->next;

}// while

}

}// if

else

printf(":::HOSPITAL NOT FOUND:::\n");

}// else if

}while(ch!='E' && ch!='e');

}

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void print_clinic ()

{

char ch='0';

int i;

clinic *p;

dr *doc;

nr *nurs;

ser *serv;

staff *staf;

while(ch!='e' && ch!='E')

{

printf("1 >Print all doctors in a given clinic\n");

printf("2 >Print all nurses in a given clinic\n");

printf("3 >Print all staff members in a given clinic\n");

printf("4 >Print all service company in a given clinic\n");

printf("E >Exit\n");

printf(" You'r choice :");

scanf(" %c",&ch);

if(ch=='e'||ch=='E') break;

printf("Enter the name of the hospital\n");

scanf("%s",name);

i=search_hosp(name);

if(i<0)

printf(":::HOSPITAL NOT FOUND:::\n");

else

{

printf("Enter the name of the clinic\n");

scanf("%s",name);

p=search_clinic(i,name);

if(p ==NULL) printf(":::CLINIC NOT FOUND:::\n");

else //if (p!=NULL)

{

if(ch=='1')

{

doc=p->drptr;

if(doc==NULL) printf(":::THERE ARE NO STORD DOCTORS IN THE CLINIC:::\n");

else{

printf("The stored doctors:\n");

while(doc !=NULL)

{

printf("%s %s\n",doc->fn,doc->ln);

doc=doc->next;

}//while

}

}//if

else if(ch=='2')

{

nurs=p->nrptr;

if(nurs == NULL) printf(":::THERE ARE NO STORED NURSES IN THE CLINIC:::\n");

else{

printf("The stored nurses:\n");

while(nurs != NULL)

{

printf("%s %s\n",nurs->fn,nurs->ln);

nurs=nurs->next;

}//while

}

}//if

else if(ch=='3')

{

staf=p->stafptr;

if(staf == NULL) printf(":::THERE ARE NO STORED STAFF MEMBERS IN THE CLINIC:::\n");

else{

printf("The stored staff members:\n");

while(staf != NULL)

{

printf("%s %s\n",staf->fn,staf->ln);

staf=staf->next;

}//while

}

}//if

else if(ch=='4')

{

serv=p->serptr;

if(serv == NULL) printf(":::THERE ARE NO STORED SERVICE COMPANIES IN THE CLINIC:::\n");

else{

printf("The stored service companies:\n");

while(serv != NULL)

{

printf("%s \n",serv->cn);

serv=serv->next;

}//while

}

}//if

}//while

}

}//if

}

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void print_doctor( )

{

dr *doc;

patient *pati;

char ch ;

int i;

clinic *p;

do{

printf("1 >Print doctor's address \n");

printf("2 >Print doctor's tel. \n");

printf("3 >Print doctor's working hours\n");

printf("4 >Print doctor's all patients\n");

printf("E >Exit\n");

scanf(" %c",&ch);

if(ch=='E'|| ch=='e')

break;

else if(!(ch=='1' || ch=='2' || ch=='3' ||ch=='4' ||ch=='e' ||ch=='E'))

printf(":::INVALIED CHOICE:::\n");

printf("Enter the name of the hospital\n");

scanf("%s",name);

i=search_hosp(name);

if(!(i>=0)) printf(":::HOSPITAL NOT FOUND:::\n");

else

{

printf("Enter the name of the clinic\n");

scanf("%s",name);

p=search_clinic(i,name);

if(p == NULL) printf(":::CLINIC NOT FOUND::: \n");

else{

printf("Enter the first and the last name of the doctor\n");

scanf("%s %s",name,ln);

doc=search_doc(p,name,ln);

if(doc == NULL) printf(":::DOCTOR NOT FOUND:::\n");

if(doc != NULL)

{

if(ch=='1')

printf("The address :%s\n",doc->add);

else if(ch=='2')

printf("Th tel. number:%s\n",doc->tel);

else if(ch=='3')

printf("The working hours:%s\n",doc->wh);

else if(ch=='4')

{

pati=doc->ptr;

if(pati==NULL) printf(":::THERE ARE NO STORED PATIENTS FOR THIS DOCTOR:::\n");

else{

printf("The stored patients:\n");

while(pati != NULL)

{

printf("%s %s\n",pati->fn,pati->ln);

pati=pati->next;

}//while

}

}//else 4

}//while

}//else

}//else

}while(ch != 'e' && ch !='E');

}

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void print_nurse ()

{

char ch ;

int i;

clinic *p;

nr *nur;

printf("1 >Print nurse's address \n");

printf("2 >Print nurse's tel. \n");

printf("3 >Print nurse's working hours\n");

printf("E >Exit\n");

scanf(" %c",&ch);

while(ch !='e' && ch!='E')

{

if(!(ch=='1' || ch=='2' || ch=='3' ||ch=='4' ||ch=='e' ||ch=='E'))

printf(":::INVALIED CHOICE:::\n");

printf("Enter the name of the hospital\n");

scanf("%s",name);

i=search_hosp(name);

if(i>=0)

{

printf("Enter the name of the clinic\n");

scanf("%s",name);

p=search_clinic(i,name);

if(p==NULL) printf(":::CLINIC NOT FOUND:::\n");

if(p!=NULL)

{

printf("Enter the fist and the last name of the nurse\n");

scanf("%s %s",name,ln);

nur=search_nurs(p,name,ln);

if(nur == NULL) printf(":::NURSES NOT FOUND:::\n");

else if(nur != NULL)

{

if(ch=='1')

printf("The address:%s\n",nur->add);

else if(ch=='2')

printf("Th tel.number:%s\n",nur->tel);

else if(ch=='3')

printf("Th working hours:%s\n",nur->wh);

}//else if

}//if (p!=NULL)

}//if(i>=0)

}

}

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void print_staff ()

{

char ch;

staff *staf;

int i;

clinic *p;

while(ch !='e' && ch!='E')

{

printf("1 >Print staff member's address \n");

printf("2 >Print staff member's tel. \n");

printf("3 >Print staff member's working hours\n");

printf("E >Exit\n");

scanf(" %c",&ch);

if(!(ch=='1' || ch=='2' || ch=='3' ||ch=='4' ||ch=='e' ||ch=='E'))

printf(":::INVALIED CHOICE:::\n");

printf("Enter the name of the hospital\n");

scanf("%s",name);

i=search_hosp(name);

if(i>=0)

{

printf("Enter the name of the clinic\n");

scanf("%s",name);

p=search_clinic(i,name);

if(p==NULL) printf(":::CLINIC NOT FOUND:::\n");

if(p!=NULL)

{

printf("Enter the fist and the last name of the staff member\n");

scanf("%s %s",name,ln);

staf=search_staff(p,name,ln);

if(staf == NULL) printf(":::STAFF MEMBER NOT FOUND:::\n");

else if(staf != NULL)

{

if(ch=='1')

printf("The address:%s\n",staf->add);

else if(ch=='2')

printf("The tel.number:%s\n",staf->tel);

else if(ch=='3')

printf("The working hours:%s\n",staf->wh);

}//else if

}//if (p!=NULL)

}//if(i>=0)

}

}

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void print_ser()

{

char ch='0' ;

int i;

ser *serv;

clinic *p;

while(ch !='e' && ch!='E')

{

printf("1 >Print service company's address \n");

printf("2 >Print service company's tel. \n");

printf("3 >Print service company's working hours\n");

printf("E >Exit\n");

scanf(" %c",&ch);

if(!(ch=='1' || ch=='2' || ch=='3' ||ch=='4' ||ch=='e' ||ch=='E'))

printf(":::INVALIED CHOICE:::\n");

printf("Enter the name of the hospital\n");

scanf("%s",name);

i=search_hosp(name);

if(i>=0)

{

printf("Enter the name of the clinic\n");

scanf("%s",name);

p=search_clinic(i,name);

if(p==NULL) printf(":::CLINIC NOT FOUND:::\n");

if(p!=NULL)

{

printf("Enter the name of the service company\n");

scanf("%s",name);

serv=search_serv(p,name);

if(serv == NULL) printf(":::SRVICE COMPANY NOT FOUND:::\n");

else if(serv != NULL)

{

if(ch=='1')

printf("The address:%s\n",serv->add);

else if(ch=='2')

printf("The tel. number:%s\n",serv->tel);

else if(ch=='3')

printf("The working hours:%s\n",serv->wh);

}//else if

}//if (p!=NULL)

}//if(i>=0)

}

}

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

void print_patient()

{

char ch='0';

patient *pati;

dr *doc;

clinic *p;

int i;

while(ch !='e' && ch!='E')

{

printf("1 > print patient's civil i.d.\n");

printf("2 > print patient's next appointment \n");

printf("E >Exit\n");

scanf(" %c",&ch);

if(!(ch=='1' || ch=='2' || ch=='3' ||ch=='4' ||ch=='e' ||ch=='E'))

printf(":::INVALIED CHOICE\n");

else{

printf("Enter the name of the hospital where the patient exists\n");

scanf("%s",name);

i=search_hosp(name);

if(i<0) printf(":::HOSPITAL NOT FOUND:::\n");

else

{

printf("Enter the name of the clinic where patient exists\n");

scanf("%s",name);

p=search_clinic(i,name);

if(p==NULL) printf(":::CLINIC NOT FOUND:::\n");

else{

printf("Enter the(first&last)name of the patient's doctor\n");

scanf("%s %s",name,ln);

doc=search_doc(p,name,ln);

if(doc == NULL) printf("DOCTOR NOT FOUND\n");

else{

printf("Enter the(first&last)name of the patient\n");

scanf("%s %s",name,ln);

pati=search_patient(doc,name,ln);

if(pati==NULL) printf("PATIENT NOT FOUND\n");

else{

if(ch=='1') printf("%s\n",pati->cid);

else if(ch=='2') printf("%s\n",pati->app);

}

}

}//else

}//else

}//else

}//while

}

/***************************************************************************************************

menu function prints the options and gets the selected option

****************************************************************************************************/

char menu ()

{

char op;

printf("*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.\n");

printf("\nI > Insert a record. \n");

printf("D > Delete a record.\n");

printf("P > Print and search for any stored info.\n");

printf("F > Find which was working at specific hours.\n");

printf("S > Search for a doctors at a given hour for particular clinic. \n");

printf("Q > Quite the program.\n\n");

printf("Pick one of these options:");

scanf(" %c",&op);

return op;

}/* end function*/

/**************************************************************************************************

the main function calles the seleced function by comparing the

selected code

***************************************************************************************************/

int main ()

{

char ch,c;

int i=0;

char date[10]; //for search for the woriking hour

clinic *p;

dr *doc;

nr *nurs;

staff *staf;

ser *serv;

for(i=0;i<10; strcpy(arr.hos,"nothing"),i++);

ch=menu();

while(ch!='q'&& ch!='Q')

{

if(ch=='I'|| ch=='i')

{

do{

printf("\nwhat do you want to insert : \n");

printf("\n1 > hospital \n");

printf("2 > clinic\n");

printf("3 > doctor\n");

printf("4 > nurse\n");

printf("5 > staff member\n");

printf("6 > Service company \n");

printf("7 > Patient\n");

printf("E > Exit\n");

printf("\nYou'r choice:");

scanf(" %c",&c);

if(c=='1')

insert_hosp();

else if(c=='2')

insert_clinic();

else if(c=='3')

insert_doc();

else if(c=='4')

insert_nurs();

else if(c=='5')

insert_staff();

else if(c=='6')

insert_ser();

else if(c=='7')

insert_patient();

else if(c=='e' || c=='E')

break;

}while(c!='E' && c!='e');

}//if

else if(ch=='D'||ch=='d')

{

do{

printf("\nwhat do you want to delete : \n");

printf("\n1 > hospital \n");

printf("2 > clinic\n");

printf("3 > doctor\n");

printf("4 > nurse\n");

printf("5 > staff member\n");

printf("6 > Service company \n");

printf("7 > Patient\n");

printf("E > Exit\n");

printf("\nYou'r choice:");

scanf(" %c",&c);

if(c=='1')

delete_hosp();

else if(c=='2')

delete_clinic();

else if(c=='3')

delete_doc();

else if(c=='4')

delete_nurs();

else if(c=='5')

delete_staf();

else if(c=='6')

delete_ser();

else if(c=='7')

delete_patient();

}while(c!='E' && c!='e');

}

else if(ch=='P'||ch=='p')

{

do{

printf("\nwhat do you want to print : \n");

printf("\n1 > hospital\n");

printf("2 > clinic\n");

printf("3 > doctor\n");

printf("4 > nurse\n");

printf("5 > staff member\n");

printf("6 > Service company \n");

printf("7 > Patient\n");

printf("E > Exit\n");

printf("\nYou'r choice:");

scanf(" %c",&c);

printf("\n:::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n");

if(c=='1')

print_hospital();

else if(c=='2')

print_clinic();

else if(c=='3')

print_doctor();

else if(c=='4')

print_nurse();

else if(c=='5')

print_staff();

else if(c=='6')

print_ser();

else if(c=='7')

print_patient();

}while(c!='E' && c!='e');

}

else if(ch=='F'||ch=='f')

do{

printf("\n:::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n");

printf("\npick one to identify his/her working hours\n");

printf("1 > doctor\n");

printf("2 > nurse\n");

printf("3 > staff member\n");

printf("4 > Service company \n");

printf("E > Exit\n");

printf("\nYou'r choice:");

scanf(" %c",&c);

if(c=='e'||c=='E')

break;

printf("\n:::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n");

printf("Enter the time:");

scanf("%s",date);

printf("Enter the name of hospital where u want to search in\n");

scanf("%s",name);

i=search_hosp(name);

if(i<0) printf("HOSPITAL NOT FOUND\n");

else{

printf("Enter the name of clinic where u want to search in");

scanf("%s",name);

p=search_clinic(i,name);

if(p==NULL) printf("CLINIC NOT FOUND");

else{

if(c=='1')

{

doc=p->drptr;

while(doc !=NULL)

{

if(strcmp(doc->wh,date)==0)

printf("%s %s\n",doc->fn,doc->ln);

doc=doc->next;

}

}

else if(c=='2')

{

nurs=p->nrptr;

while(nurs !=NULL)

{

if(strcmp(nurs->wh,date)==0)

printf("%s %s\n",nurs->fn,nurs->ln);

nurs=nurs->next;

}

}

else if(c=='3')

{

staf=p->stafptr;

while(staf !=NULL)

{

if(strcmp(staf->wh,date)==0)

printf("%s %s\n",staf->fn,staf->ln);

staf=staf->next;

}

}

else if(c=='4')

{

serv=p->serptr;

while(serv !=NULL)

{

if(strcmp(serv->wh,date)==0)

printf("%s\n",serv->cn);

serv=serv->next;

}

}

}

}

}while(c!='E' && c!='e');

else if(ch=='S'||ch=='s')

{

printf("Enter the time to show doctors that are not working

#2

يعني ماتعرفوون ؟؟؟؟؟؟؟؟؟؟؟؟

#3

Hash is just function that generate address's.....that's it

It'a a sorting techniques same as bubble and selection sort but this one is more complix and more useful

About your Assginment you decide if you're going to use a static memory "Array" or dynamic "Linked List" depending on the collision resolution

Meanning you're going to use the array for Clinic's ,Staff Member's and Service Compnay ,and you're going to use linked list for Nurse's ,Patients and Dr.'s

Good Luck

it's an easy assignment really...just need some work

let me know if you didn't get anything

#4

السلام عليكم...

أخي انا خبرتي بال ++C قديمة ولا اكاد اذكر شيئا...

لكن بانسبة للهاش... انا تعاملت معه في لغات برمجة اخرى وهو سهل وجميل.

اشرح لك الفكرة عسى أن انفعك...

الهاش هو data structur تستطيع مبدئيا أن تنظر اليها على أنها Array. ولكن بينها وبين ال Array بعض الاختلافات.

الاختلاف الأهم هو أن ال Index لل هاش قد يكون أي شيئ وليس بالضرورة أن يكون رقما Integer موجبا كما هو الحال في ال Array

في ال Array كنا نقول

int Arr[5];

على سبيل المثال.

وبهذا نعرّف Array حجمها 5 من نوع integer .

في الهاش انت لا تحدد الحجم مسبقا بل (كما الحال في ال linked list ) تضيف اي عنصر اضافة وليس هناك حد اقصى.

ال index في الهاش يسمى : key

والقيمة المراد ادخالها تسمى : value

اذا كان اسم الهاش هو hash1 على سبيل المثال وتريد ان تكتب رقم الهاتف ك index واسم صاحب الهاتف ك value فستكتب (تماما كما في ال Array) أن

hash1[key] =value;

نوع المدخل في ال key وال value غير محدد فبإمكانك ان تجعل اي منهما من نوع char أو int أو long أو حتى اي object تريده.

قلت لك ان خبرتي في ال ++C قديمة. سأكتب هنا مما أحفظ كيفية استخدام ال hash في ال #C ولا اظنها تختلف كثيرا عنها في اي لغة برمجة اخرى.

Hashtable table1=new Hashtable();
table1.Add("1234546","Mohammad");
table1.Add("987654","Ali");

علامات الاقتباس تعني ان المدخل هو نص (string)

لاحظ أن ادخال ال key وال value له طريقتان... احداهما تماما كما هو الحال في ال Array .

والآن اذا كنت تعرف رقم الهاتف وتريد ان تستخرج صاحب هذا الرقم تكتب

string name= (string) table1["123456"];

وضعنا (string) قبل اسم الهاش لأن القيمة التي في الهاش من الممكن ان تكون أي شيء وليس بالضرورة ان تكون string ولذلك نحدد اننا وضعنا في الهاش قيمة string ونريد استخراج قيمة لوضعها في متغير من نوع string ايضا.

الآن المتغير النصي name يحتوي على القيمة "Mohammad " صاحب رقم الهاتف "123456".

ارجو أن تكون توضحت لك الفكرة أخي. وأرجو ايضا ان تستطيع تطبيقها على ال ++C.

وفقكم الله...

تم تعديل هذه المشاركة بواسطة Andalus في 20 ديسمبر 2006 في 22:37

#5

andalus

انا ابي اطبقها على السي مو السي بلس بلس

انا فاهمه الفكره بس البرمجه صعبه زانا لقيت برامج بس معقده و مومفهومه

اخوي اذا عندك برنامج عن الهاش اي برنامج و يكون بالسي ويشتغل من غير اخطاء

انا راح اطبق عليه حتى لو كان برنامج بسيط المشكله اني كل مره احاول تطلعلي اخطاء ماعرف اعدلها .

O'nile

الكلام سهل !

انا فاهمه الفكره اكثر مما تظن .

بس المشكله بالبرمجه مثلا ال trie بال dynamic hash ماعرف شلون ابرمجه دورت بالكتب على طريقه لبرمجته مالقيت كلها شرح !

ابي مثال واضح و من غير اخطاء مثال بسيط عشان افهم البرمجه له

بعدين شي ثاني المستشفيات لازم تكون Array و من كل cell بال array يطلع بوينتر على مجموعه من ال clinics اللي موجوده بالمستشفى و من كل clinic تطلع 4 pointers للعاملين بها انا شلون اربط كل هذولا مع بعض بستخدام الهاش !

ممكن توضيحك يكون بامثله واضحه بما ان الاهوم روك سهل بنظرك لهدرجه !

وشكرا

#6

قد بحثت على الانترنت ووجدت رابطين ارجو ان يكونا ذوي فائدة ..

الرابط الأول :

http://www.opensource.apple.com/darwinsour...s-590/as/hash.c

الرابط الثاني

http://www.codeproject.com/cpp/dynopenhashtable.asp

عفوا لكن خبرتي في السي والسي بلس بلس قليلة وقديمة... والا لكنت بذلت جهدا اكبر في مساعدتك.

مع امنياتي بالتوفيق ...

#7

Becuse i'm tired of writing comments i didn't write any ,but if there was somthing that you didn't understnd just let me know

at the end of this excution the Tire should be like:

1)Bucket 1 wich is located at the most left in the left "subtree" will have: A0 ,B0

2)Bucket 2 wich is located at the most right in the left "subtree" will have: C2

3)Bucket 3 wich is located at the most left in the right "subtree" will have: A1 ,B1

4)Bucket 4 wich is located at the most right in the right "subtree" will have: A1 ,B1

in other word's it should be same as Trie in page number 13 in our notes

you can debug it at the end and look at the Trie yourself ,just make it stop at (cin>>count)

#include<iostream>

#include<string>

using namespace std;

typedef struct Bucket_Rec

{

string slot1 ,slot2;

}Bucket_Info;

typedef struct Trie

{

Trie *one;

Trie *zero;

Bucket_Info *link_Bucket;

}Trie_Info;

int hash(string ,int);

int main()

{

char ch;

string A1[8] = {"A0","A1","B0","B1","C2","C3"};

int x ,count;

Trie_Info *Trie_Ptr;

Trie_Info *temp_Ptr;

Trie_Ptr = new Trie_Info;

Trie_Ptr->one = NULL;

Trie_Ptr->zero = NULL;

Trie_Ptr->link_Bucket = NULL;

for(count=0 ; count<6 ; count++)

{

temp_Ptr = Trie_Ptr;

x=hash(A1[count] ,1);

if(x>=1)

{

if(temp_Ptr->one == NULL)

{

temp_Ptr->one = new Trie_Info;

temp_Ptr->one->one = NULL;

temp_Ptr->one->zero = NULL;

temp_Ptr->one->link_Bucket = NULL;

}

temp_Ptr = temp_Ptr->one;

x=hash(A1[count] ,2);

if(x>=1)

{

if(temp_Ptr->one == NULL)

{

temp_Ptr->one = new Trie_Info;

temp_Ptr->one->one = NULL;

temp_Ptr->one->zero = NULL;

temp_Ptr->one->link_Bucket = NULL;

}

temp_Ptr = temp_Ptr->one;

if(temp_Ptr->link_Bucket == NULL)

{

temp_Ptr->link_Bucket = new Bucket_Info;

temp_Ptr->link_Bucket->slot1 = A1[count];

}

else

temp_Ptr->link_Bucket->slot2 = A1[count];

}

else if(x==0)

{

if(temp_Ptr->zero == NULL)

{

temp_Ptr->zero = new Trie_Info;

temp_Ptr->zero->one = NULL;

temp_Ptr->zero->zero = NULL;

temp_Ptr->zero->link_Bucket = NULL;

}

temp_Ptr = temp_Ptr->zero;

if(temp_Ptr->link_Bucket == NULL)

{

temp_Ptr->link_Bucket = new Bucket_Info;

temp_Ptr->link_Bucket->slot1 = A1[count];

}

else

temp_Ptr->link_Bucket->slot2 = A1[count];

}

}

else if(x==0)

{

if(temp_Ptr->zero == NULL)

{

temp_Ptr->zero = new Trie_Info;

temp_Ptr->zero->one = NULL;

temp_Ptr->zero->zero = NULL;

temp_Ptr->zero->link_Bucket = NULL;

}

temp_Ptr = temp_Ptr->zero;

x=hash(A1[count] ,2);

if(x>=1)

{

if(temp_Ptr->one == NULL)

{

temp_Ptr->one = new Trie_Info;

temp_Ptr->one->one = NULL;

temp_Ptr->one->zero = NULL;

temp_Ptr->one->link_Bucket = NULL;

}

temp_Ptr = temp_Ptr->one;

if(temp_Ptr->link_Bucket == NULL)

{

temp_Ptr->link_Bucket = new Bucket_Info;

temp_Ptr->link_Bucket->slot1 = A1[count];

}

else

temp_Ptr->link_Bucket->slot2 = A1[count];

}

else if(x==0)

{

if(temp_Ptr->zero == NULL)

{

temp_Ptr->zero = new Trie_Info;

temp_Ptr->zero->one = NULL;

temp_Ptr->zero->zero = NULL;

temp_Ptr->zero->link_Bucket = NULL;

}

temp_Ptr = temp_Ptr->zero;

if(temp_Ptr->link_Bucket == NULL)

{

temp_Ptr->link_Bucket = new Bucket_Info;

temp_Ptr->link_Bucket->slot1 = A1[count];

}

else

temp_Ptr->link_Bucket->slot2 = A1[count];

}

}

}

cin>>count;

return 0;

}

int hash(string A1 ,int bit_num)

{

int x ,y;

char ch;

ch = A1[1];

bit_num = 1<<bit_num-1;

y = ch & bit_num;

return y;

}

#8

ok i rewrite it with recursion ,it should be easeir and nicer with some comments ,if you have any more quistions ,please don't hesitate to ask

#include<iostream>

#include<string>

using namespace std;

typedef struct Bucket_Rec

{

string slot1 ,slot2;

}Bucket_Info;

typedef struct Trie

{

Trie *one;

Trie *zero;

Bucket_Info *link_Bucket;

}Trie_Info;

typedef Trie_Info *Trie_Ptr;

int hash(string ,int);

Trie_Ptr Dynamic_Hash(Trie_Ptr ,string ,int ,int);

int main()

{

char ch;

string A1[8] = {"A0","A1","B0","B1","C2","C3"};

int x ,count;

Trie_Ptr home;

home = new Trie_Info;

home->one = NULL;

home->zero = NULL;

home->link_Bucket = NULL;

for(count=0 ; count<6 ; count++)//this counter becuse we have 6 strings if you

home = Dynamic_Hash(home ,A1[count] ,1 ,2);//want more than 6 just call it from

//a function

cin>>count;

return 0;

}

//------------------------------------------------------------------------------

Trie_Ptr Dynamic_Hash(Trie_Ptr temp_Ptr ,string Identfier ,int bit_num ,int max)

{// home pointer Identefier bit# you'r #of bit

int x; // comparing you'll compare

if(bit_num <= max)

{

x=hash(Identfier ,bit_num);

if(x>=1)

{

if(temp_Ptr->one == NULL)

{

temp_Ptr->one = new Trie_Info;

temp_Ptr->one->one = NULL;

temp_Ptr->one->zero = NULL;

temp_Ptr->one->link_Bucket = NULL;

}

temp_Ptr->one = Dynamic_Hash(temp_Ptr->one ,Identfier ,bit_num+1 ,max);

}

else if(x==0)

{

if(temp_Ptr->zero == NULL)

{

temp_Ptr->zero = new Trie_Info;

temp_Ptr->zero->one = NULL;

temp_Ptr->zero->zero = NULL;

temp_Ptr->zero->link_Bucket = NULL;

}

temp_Ptr->zero = Dynamic_Hash(temp_Ptr->zero ,Identfier ,bit_num+1 ,max);

}

}

else

{

if(temp_Ptr->link_Bucket == NULL)

{

temp_Ptr->link_Bucket = new Bucket_Info;

temp_Ptr->link_Bucket->slot1 = Identfier;

}

else

temp_Ptr->link_Bucket->slot2 = Identfier;

}

return temp_Ptr;

}

//------------------------------------------------------------------------------

int hash(string identefier ,int bit_num)

{//just return the bit of 0 or >1 "means 1"

int x ,y;

char ch;

ch = identefier[1];

bit_num = 1<<bit_num-1;

y = ch & bit_num;//clearing all bit's except the one you'll compare with

return y;

}

#9

andalus

انت ماقصرت معاي اخوي الملف اللي حطيت الرابط كان مفيد

شكرا على اهتمامك بمساعدتي و اتمنى اني افيدك في يوم.

O'nil

انا نزلت الكودين و قاعده اجيك عليهم

انا متاكدة انه بيكون عندي شويه استفسارات بس اشاء الله بعد مادرس الكود و اطبقه على الهوم ورك

مشكوووور حييل على المساعده و اتمنى اني مازعجتك

#10

الحمد لله أنك استفدت من الروابط...

لا تنسونا من صالح دعائكم....

ونتمنى التوفيق للجميع..

#11

O'nil

hi again

the code u gave me was very clear and it did help me soo much

my problem with dynamic hashing is gone now and thanks for u for that

and now can u help me with static hashing !

it will be really great if u have a code for static hashing so after studying it i will be able to complete my work

i really understand from reading codes more that explanations with words

and every time i find code for static hash on the internet it come with erorrs

i just want a simple code that create hash table and has insert ,delete and search functions

i really need ur help &thanks again;

تم تعديل هذه المشاركة بواسطة AIZ في 22 ديسمبر 2006 في 23:41

#12

Since the static hash contain more then one collision resolving and becuse your quistion is to long to program i wrote a small example on static hash on linear probing ,hope it helps...still ig you have any quistion just let me know

#include<iostream>

#include<string>

using namespace std;

typedef struct array

{

string name;

int flag;

}hash_table;

hash_table table[5];

void set_flag();

int hash(string);

int main()

{

string s1;

int x ,count;

do

{

cout<<"\nEnter a string (input ""end"" to quit):";

cin>>s1;

x=hash(s1);

set_flag();

while(table[x].flag==0 && table[x].name.compare(s1)!=0 && table[x].name.compare("")!=0)

{//1st cond. for list full....2nd cond. for name exist....3rd cond. for empty

table[x].flag=1;

x++;

x=x%5;//so that if we start from the middle and reched the end and didn't

}//check all the list

if(table[x].flag==1)

cout<<"\nHash table is full";

else if(table[x].name.compare(s1)==0)

cout<<"\nString you entered already exist";

else

table[x].name = s1;

set_flag();//to reset flag list

}while(s1.compare("end")!=0);

cin>>count;

return 0;

}

//------------------------------------------------------------------------------

int hash(string name)//this hash func. take a string and multiply it's char. on

{//it's pos

int temp ,add ,pos;

char ch;

for(pos=0 ; pos<30 ; pos++)

{

ch = name[pos];

if(ch!='\0')

{

temp=int(ch*pos);

add=add+temp;

add=add%5;

}

else

pos=30;

}

return add;

}

//------------------------------------------------------------------------------

void set_flag()//to set the flags

{

int count;

for (count=0 ; count<5 ; count++)

table[count].flag=0;

}

#13

O'nil

god bless u :)

#14

O'nil

god bless u :)

هذا الموضوع مغلق.

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…