home *** CD-ROM | disk | FTP | other *** search
/ Go64! / Go64_2000-07_2000_CSW_Side_B.d64 / hashing(deutsch) (.txt) < prev    next >
Commodore BASIC  |  2023-02-26  |  1KB  |  52 lines

  1. 1 m=29:rem liste fuer 197 eintraege
  2. 2 gosub 10
  3. 3 goto 300
  4. 10 rem - hashfunktion definieren -
  5. 11 rem - und tabelle initialisieren -
  6. 12 def fn modm(n)=n-int(n/m)*m
  7. 13 def fn h(k)=fn modm(fn modm(k)+i)
  8. 14 dim t(m): rem arrays
  9. 15 dim a$(m):rem dimensionieren
  10. 16 for j=0 to m:t(j)=-1:next:rem loeschen
  11. 17 return
  12. 30 rem ---- hash insert ----
  13. 40 i=0
  14. 50 j=fn h(k)
  15. 60 if t(j)<0 then t(j)=k:return
  16. 70 i=i+1:if i < m goto 50
  17. 80 print "?hash table overflow error":stop
  18. 90 j=-1:return
  19. 100 rem ---- hash search ----
  20. 110 i=0
  21. 120 j=fn h(k)
  22. 130 if t(j)=k then return
  23. 140 i=i+1
  24. 150 if (t(j)=-1) or (i=m) then j=-1:return
  25. 160 goto 120
  26. 170 rem ---- hash delete ----
  27. 180 gosub 110:if j=-1 then return
  28. 190 t(j)=-2:return
  29. 300 print "[147]1.neuer eintrag"
  30. 310 print "2.suchen"
  31. 320 print "3.loeschen"
  32. 330 get x$:if x$="" then goto 330
  33. 340 if x$="1" then gosub 1000
  34. 350 if x$="2" then gosub 2000
  35. 360 if x$="3" then gosub 3000
  36. 370 goto 300
  37. 1000 input "name";n$
  38. 1010 input "telefonnummer";k
  39. 1020 gosub 30
  40. 1030 if j=-1 then print "liste voll!"
  41. 1040 if j>=0 then print "listenposition:";j
  42. 1050 a$(j)=n$:poke198,0:wait198,1:return
  43. 2000 input "telefonnummer";k
  44. 2010 gosub 100
  45. 2020 if j=-1 then print"nicht gefunden!":goto2050
  46. 2030 print "listenposition:";j
  47. 2040 print "name:";a$(j)
  48. 2050 poke198,0:wait198,1:return
  49. 3000 input "telefonnummer";k
  50. 3010 gosub 170:print"eintrag geloescht"
  51. 3020 poke198,0:wait198,1:return
  52.