Il 0% ha trovato utile questo documento (0 voti)
3 visualizzazioni8 pagine

E 2

333333
Copyright
© All Rights Reserved
Per noi i diritti sui contenuti sono una cosa seria. Se sospetti che questo contenuto sia tuo, rivendicalo qui.
Formati disponibili
Scarica in formato PDF o leggi online su Scribd
Il 0% ha trovato utile questo documento (0 voti)
3 visualizzazioni8 pagine

E 2

333333
Copyright
© All Rights Reserved
Per noi i diritti sui contenuti sono una cosa seria. Se sospetti che questo contenuto sia tuo, rivendicalo qui.
Formati disponibili
Scarica in formato PDF o leggi online su Scribd
zag 1/17124 Trang thet Bit div vao lie Kétthde Wie Thol gian thyre ign idm ibm Hash: Xom flint thir (trang 1 td tng 66 6) [BK-LMS Da xong ‘Thar B0, 29 thang 102024, 2:57 PM ‘rir Hoi, 1 théng 11 2024, 607 PM 13. Cac ngay 3.0% 6.00/60 10,00 iran 10,00 (100%) ntps:[Link] vnfmadiquireview pip ?attenpt=46381794cmid=4610798show al-0 18 zag 11/17124 Hash: Xom flim tam thir (trang 1 ted t8ng 66 6) [BK-LMS Implement the put method in template class XHashMap representing the Hash Table. The Hosh Table is implemented wit ‘Open Hashing for handling collision, using a Sinaly linked Is ta store keys with the some index. The description of the. methods givenin the code. int hashFunction(int key, int capacity) { return key % capacity: ) template loss XHashMap { publ: ‘loss Entry { publ: Kkey: V valve Eny* next Enry(k key. V value, Eniry* next = 0} ( ‘hisokey = keys thisvalue = value; thisonext = next: ) : private: Eny™ table; // hash table Int capacity; // sie for the hash toble int coun pubic: 11 Constructor XHashMopt { fable = new Entry*[eopecity]: Hresel table 10.0 for (it i= 0:1 < capacity: r+) { tablet =0: > ) ~XHashMapii{// Destructor Remove all enties in the current map forint idx=0; idx capacity exe) Entry" entry = this>table fide]: whilefentry = OW Entry “next = entry>next delete entry: entry = next: y ) HRemeve table delete [Hloble: } JJ YOUR ANSWER ntps:[Link] vnfmadiquiireview pip ?attenpt=46381794cmid=4610798show al-0 28 zag 1/17124 11 prin table method {for testing) void prinfTable() const { cout << "The hash table is shown below-— for {int i= 0:1 < capacity: ++] { Entry" entry = table: cout << "Index" <next y cout << endl; , coutc< Ars + : For exampl Test Result nop. put, 108); [Link] table); “the hash table 4s shown below Index @ nde Index 2: Index 5: Index 6: (6, 106) Index 7: index nde 9 [Link](®, 18); nop. put(1@, 100); 1/ adding rot seplacing nop. prineTabie(); - The hash table {5 shown below Index 8: (18, 180) (@, 12) Incex 2 nce 3: Index 4 index 5 [Link](t, 15)5 [Link](1, 200); // updating new value for existing index [Link]()s the hash table is shown below nde 2) 2: (a, 200) snd 2 sine Ineex 6: nce 7: nce @ nde 9) A Answ (penatty regime: 0.0. 0.0.0, 100%) Reset answor ntps:[Link] vn/madiquizreview php ?attenpt=46381798cmid=4610788show al-0 38 zag 11/17124 Hash: Xom flint thir (trang 1 td tng 66 6) [BK-LMS a [void pur(int key, int value) ( 2") 17000: compute the index using the hash function 3 4 | r7vovo: check if the key exists in the Linked List at the index, update if found 5 5 | /yrop0: 1 the key doesn't exist, create and insert 2 new entry 7 8 | 77000: tnerement the count and ensure load Factor by resizing if needed 3 | int ancex-hashrunetion(key, capacity); ae | entry *curstablefindex]; aa | bool eanfind=faise; az} if(curs=nuliper) ¢ 3 ‘ensureLoadFactor (count +1); 15 AndexchashFunction(key, capacity); 16 curenew Entry(key, value) 3 v ‘table[index]=cur; 1 135] else (wniie(curt 2 | (curd kay n ‘cur->valve-values 2 ccanfand=true} 2 break; 2 > 2s ‘curscur-onex 26 Af (eanfind==0) ¢ 2 ‘ensureLoadFacton(count+t); 2 counts 23 ndexchashFunet ion(key, eapacity)s 2» curenew Entry(key,value,table[index]); n ‘sable(index]=curs od > af) x |p 36 -|void ensuretoadtactor(int current_size) ( 37 | //7000; Calculate the waximin allowed size based on the load factor (0.75 * capacity) 28 39 | s/7T000: IF the current size exceeds om equals the max allowed size, trigger rehashing 42 | 1000: calculate the new capacity (1.5 tines the ol¢ capacity) 2 43 | /t000: call the rehash function with the new capacity a@ | Gouote nax-e.75*capacity; 45 | int [Link]; a6 | i¢((double)current_size>=nax) rehash(newe); 47 as fy 49 50 -|void rehasn(int newcapacity) ¢ s1 | //1000: store the current table and capacity 52 53 | 1/7000: create a new table with the new capacity and update the capacity se 55 | //1000: Instsalize the nex table with nuliptr values 56 57 | //1000: For each index in the olé table 5a] // ~ Traverse the Linked List at that index 52] // = Recanpute the new index for each entry using the new capacity 60 | // = Insert the entry into the nex table at the reconputed index 6 62 | /1000: Delete a1 entries in the old table by traversing each Linked List and deleting nodes a ntps:[Link] vn/madiquireview php ?attenpt=46381794cmid=4610798show al-0 48 zag 19/17124 Hash: Xom flint thir (trang 1 td tng 66 6) [BK-LMS Test Expected Got Y | [Link](s, 100); op. prineTable(); ° x 2: 3 st Incex 5: (6, 18) Index 6: (6, 100) Y | [Link](@s 2095 coccsooThe hash table ds | ---------The hash table ds [Link](18, 108); // adding rot shun below ---nnnno--= shown below replacteg index 8: (49, 188) (@, 22) Tndex @: (20, 188) (0, 10) op. prineTable(); neex 2 2 Inaex 2: Tax 3: Tex €: naex 5 Index 6: Y | [Link] 2595 - “The hash table 4s [Link](t, 200); 17 updating new value | shown belowe-nnnnn----= {for existing index index 0 op. prineTable(); ngex 1: (2, 228) Teaex Teaex 5: Traex 6: index 7: rnaex 8: op. op. ap. put(1et, 580); put(1et, 289); pet<1e1, 308); printtabte()5 shen below redex @: Index 1: (201, 3¢0) redex 2 Teaex 6: Taex 7: Ieaex 8 rndex 9: ntps:[Link] vn/madiquireview php ?attenpt=46381794cmid=4610798show al-0 58 zag 11/17124 Hash: Xom flim tam thir (trang 1 ted tng 66 6) [BK-LMS Test Expected Yeap. pee(a7a, 912); op. put(557, 367); [Link](738, 622); op. put(985, 47); rap. pus(a24, 315)3 rap. print Table); The hash table is Index 4: (424, 315) (874, 912) Incex 5: (985, 477) ncex 7: (587, 367) Index 8: (738, 612) Tndex 42 (424, 325) (874, 912) Index 6: (986, 47) Index 7: (557, 367) Tedex 8: (738, 612) Yeap. pec, 588); rap. put(798, 999); rap. pur(380, 432); op. pur(678, 805); op. put(a32, 227); [Link](883, 374); rap. put(112, 596)3 ap. pur(s26, 324)3 rap. put(242, 890); rap. pur(#32, 410); rap. prinetable()s - “The hash table 4s shown below Incex @: (248, 896) index 3: (678, 805) Tex 4 Teaex 5: (359, 432) Traex 6: Incex 7: (232, 596) index 18: (799, 989) Index 11: (926, 314) Index 12: (432, 410) Index 13: (883,374) naex 145 The hash sable 4s shaun below : Index 6: (248, 890) Index 22 Tndex 3: (678, 805) Tdex & Index 5: (350, 432) Index 6: Index 7: (312, 596) Index ndex 9: Index 18: (732, 999) Tndex 12: (926, 316) Tedex 12: (432, 410) Trdex 13: (883, 374) Index 34 Yap. pex(s1e, 789); op. put(734, 645); [Link](sie, 332); op. put(3et, 981); rap. put(218, 473); rap. put(653, 550); rap. pur(48@, 286); rap. pur(S86, 998); rap. por(8e8, 359); [Link](S1e, 732); op. printTable(); . “the nash table 1s sown below naex @: (518, 732) (239, 473) (482, 260) Index 1: (556, $90) Tex 2 naex 5: (653, 550) (om, 9a) (08, 359) (731, 645) Index 0: (518, 732) (218, 473) (ae, 260) Index 1: (556, 990) Iden 2: Index 32 Index 2 Index 5: Tndex 8: (653, 550) Index 9 Index 20 Index 12: (341, 981) Index 2: Iedex 13: (898, 359) Index 14: (734, 64) ntps:[Link] vn/madiquireview php ?attenpt=46381794cmid=4610798show al-0 58 zag 11/17124 Hash: Xom flim tam thir (trang 1 ted tng 66 6) [BK-LMS op. put(753, 922); rap. put (642, 583); rap. put(191, 774); rap. put(858, 427); op. por(77@, 162); rap. por(38@, 346); rap. pur(s29, 988); [Link](); Test Expected Yeap. pet(sen, 238); - The hash table is [Link](1ea, 878); shown below [Link](eah, 722); rndex 2 naex 1: (601, 238) (482, 712) Taex 2 Tex 3: (753, 922) Iraex &: (528, 908) ncex 5: (988, 346) (778, 161) rnaex 6: naex 7. Index 11: (391, 774) Index 12: (642,583) Index 13: (348, 878) Index 14: (884, 417) redex 1: (601, 256) (481, 712) Index 2: Trdex 3: (753, 922) Index 42 (528, 908) Index 5: (989, 346) (772, 181) Index 12: (191, 774) Trdex 12: (642, 583) Index 23: (148, 878) Index 14: (888, 427) VY |[Link], 583); rap. put(143, 22293 ap. put(143, 735)3 rap. put(143, 900)3 rap. por(143, 581); rap. por(143, 162); rap. por(143, 348); [Link](103, 642); op. put(aes, 924); op. put(14s, 542); rap. printTable()s cooo-The nash table 45 shown below eax Iraex rnaex (23, 51) Tax naex Tne hash table 4s Yap. pits, 668); op. put(312, 305); op. put(232, 763); op. put(222, 102); rap. put(a52, 65293 rap. put(582, 836); rap. pur(672, 129); rap. por(762, 432); rap. por(892, 923); op. put(982, 469); op. printTable(); . the nash table 1s sown below Teaex 1 Index 2: (452, 651) (542, 836) Tex 3: naex 6: naex 7: (982, 499) (892, 925) (232, 763) (322, 181) Index 9 naex 105 Tex 1: Index 12: (762, 432) (332, 664) (312, 305) (672, 129) Index 2: (452, 651) (542, #36) Iden 3: Index 2 Index 52 Index 6: Index 7: (982, 489) (892, 925) (232, 743) (322, 102) Index 9 Index 20 Index 12 Index 12: (762, 432) (022, 664) (212, 305) (672, 129) Index 3 rndex 1 Possed all tesisl for this submision: 1.00/1,0, ntps:[Link] vn/madiquireview php ?attenpt=46381794cmid=4610798show al-0 78 zag 19/17124 Hash: Xom flint thir (trang 1 td tng 66 6) [BK-LMS hitps:ims hemut edu imodiquzireview pho attempt=46381738&emid=461079&show al-O 88

Potrebbero piacerti anche