forked from microdevweb/PB_AVL_TREE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLK_compare.pb
104 lines (100 loc) · 3.83 KB
/
LK_compare.pb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
;**********************************************************************************************************************
;* PROJECT : AVL_TREE
;* PROCESS : manage a avl tree
;* FILE : main.pbi
;* CONTENT : main program
;* AUTHOR : microdedWeb
;* DATE : 2019/12/18
;**********************************************************************************************************************
;* IMPORT
;**********************************************************************************************************************
EnableExplicit
;**********************************************************************************************************************
;* STRUCTURES / DEFINE / ENUM
;**********************************************************************************************************************
Structure people
fname.s
sname.s
id.l
EndStructure
#DATA_FILE = "import/data.csv"
;**********************************************************************************************************************
;* PROTOTYPE OF FUNCTION
;**********************************************************************************************************************
Declare load_data()
Declare ask()
;**********************************************************************************************************************
;* GLOBAL VARIABLES
;**********************************************************************************************************************
Global NewList myPeople.people()
;**********************************************************************************************************************
;* RUN PROGRAM
;**********************************************************************************************************************
OpenConsole("AVL Tree LK compare")
EnableGraphicalConsole(1)
PrintN("Please wait we load above 450.000 records, that can be take some time")
load_data()
ask()
;**********************************************************************************************************************
;* FUNCTIONS
;**********************************************************************************************************************
Procedure load_data()
Protected d.s,i
Protected t = ElapsedMilliseconds(),te.f,txt.s
; read data file
OpenFile(0,#DATA_FILE)
While Eof(0) = 0
d = ReadString(0)
If i > 0
AddElement(myPeople())
myPeople()\id = Val(StringField(d,1,";"))
myPeople()\fname = StringField(d,3,";")
myPeople()\sname = StringField(d,4,";")
EndIf
i + 1
Wend
te = (ElapsedMilliseconds() - t) / 1000
txt = Str(i-1)+" data are loaded in "+StrF(te,2)+" seconds"
PrintN(txt)
Input()
EndProcedure
Procedure ask()
Protected choice.s
Protected.people *p,*f
Protected t.f,te.f,found.b = #False
Repeat
ClearConsole()
Print("Enter a id of we look for (betwenn 100008 and 2345813) or empty for exit : ")
choice = Input()
If Len(choice)
t = ElapsedMilliseconds() ; for calculate the elapsed time
te = 0
found = #False
ForEach myPeople()
If myPeople()\id = Val(choice)
found = #True
Break
te = ElapsedMilliseconds() - t
EndIf
Next
If Not te
te = ElapsedMilliseconds() - t
EndIf
PrintN("Request finished in "+StrF(te,2)+" ms")
If found
Print("First name : "+myPeople()\fname + " Surname : "+myPeople()\sname + " id : "+Str(myPeople()\id))
Else
Print("This id : "+choice+" is not found ")
EndIf
Input()
EndIf
Until Not Len(choice)
EndProcedure
Procedure free(*d.people)
FreeStructure(*d)
EndProcedure
; IDE Options = PureBasic 5.71 LTS (Windows - x64)
; CursorPosition = 91
; FirstLine = 79
; Folding = -
; EnableXP