inf
and inf2
. Hint: whenever you find yourself reusing names, you are making a mistake. Back to this in a second.read()
function's need to access inf
.read()
and inf
have the single purpose of reading your input “element.txt” file, why not move everything to that function?
|
|
|
|
|
|
f
is never explicitly closed? It is closed when it goes out of scope, just like it should. And it does not exist anywhere else in the program — just in the one small function it needs to. This highlights one of the errors with using global variables in general, and in this case, a global file stream: you forgot to close inf2
. It only closes when your program terminates. For this program, of course, it is not an error, but in larger projects it can become a serious resource leak.sort()
algorithm sorts the array of elements by weight. But your binary search (called “locate”) searches by name (“elem”). See what went wrong?
|
|
|
|
|
|
|
|
|
|
H 1.008 Li 6.94 Na 22.990 K 39.098 Rb 85.468 Cs 132.91 Fr 223 Be 9.0122 Mg 24.305 Ca 40.078 Sr 87.62 Ba 137.33 Ra 226 Sc 44.956 Y 88.906 La 138.91 Ac 227 Ti 47.867 Zr 91.224 Hf 178.49 Rf 267 Ce 140.12 Th 232.04 V 50.942 Nb 92.906 Ta 180.95 Db 268 Pr 140.91 Pa 231.04 Cr 51.996 Mo 95.95 W 183.84 Sg 269 Nd 144.24 U 238.03 Mn 54.938 Tc 97 Re 186.21 Bh 270 Pm 145 Np 237 Fe 55.845 Ru 101.07 Os 190.23 Hs 269 Sm 150.36 Pu 244 Co 58.933 Rh 102.91 Ir 192.22 Mt 278 Eu 151.96 Am 243 Ni 58.693 Pd 106.42 Pt 195.08 Ds 281 Gd 157.25 Cm 247 Cu 63.546 Ag 107.87 Au 196.97 Rg 282 Tb 158.93 Bk 247 Zn 65.38 Cd 112.41 Hg 200.59 Cn 285 Dy 162.50 Cf 251 B 10.81 Al 26.982 Ga 69.723 In 114.82 Tl 204.38 Nh 286 Ho 164.93 Es 252 C 12.011 Si 28.085 Ge 72.630 Sn 118.71 Pb 207.2 Fl 289 Er 167.26 Fm 257 N 14.007 P 30.974 As 74.922 Sb 121.76 Bi 208.98 Mc 290 Tm 168.93 Md 258 O 15.999 S 32.06 Se 78.971 Te 127.60 Po 209 Lv 293 Yb 173.05 No 259 F 18.998 Cl 35.45 Br 79.904 I 126.90 At 210 Ts 294 Lu 174.97 Lr 266 He 4.0026 Ne 20.180 Ar 39.88 Kr 83.798 Xe 131.29 Rn 222 Og 294 |
Al(2)O(3)SiO(2) NiC(4)H(6)O(4) Na(2)VO(4) Na(3)P(5)O(4) TeCl(4) V(2)O(5) HCONHCH(2)CH(2)OH ZnC(4)H(6)O(4) UO(2)N(2)O(6)H(2)O FeTiO(3) MgC(4)H(6)O(4) C(16)N(33)OH AgSiF(6)MgOH(6)O(3) NiSO(4)N(2)H(4)SO(4)H(12)O(6) Tl(2)S(3)O(12)H(14)O(7) CBr(4) ZnCO(3) UO(2)CO(3) ThS(2)O(8) H(4)P(2)O(5) H(2)SeO(5) K(2)Cr(2)O(7) K(2)PtI(6) |