' Anwendung Rangfunktion Type Vektor x As Single y As Single z As Single Declare Constructor() Declare Constructor(x As Single, y As Single, z As Single) Declare Function toString() As String End Type Constructor Vektor() x = 0.0 y = 0.0 z = 0.0 End Constructor Constructor Vektor(x As Single, y As Single, z As Single) This.x = x This.y = y This.z = z End Constructor Function Vektor.toString() As String Return "[" + Str(x) + "," + Str(y) + "," + Str(z) + "]" End Function Operator<(a As Vektor, b As Vektor) As Integer ' Wie zuvor erwähnt Beträge bzw. dessen Quadrate vergleichen Return a.x * a.x + a.y * a.y + a.z * a.z < b.x * b.x + b.y * b.y + b.z * b.z End Operator ' type T As Double #Define T Double #Include "rangfunktionmodul.bi" #Undef T #Define T String #Include "rangfunktionmodul.bi" #Undef T #Define T Vektor #Include "rangfunktionmodul.bi" #Undef T Dim d(...) As Double => { 6.5, 1.7, -2.2, 5.4 } Dim q(...) As String => { "Andy", "Beat", "Yolanda", "Xaver", "Emil" } Dim v(...) As Vektor => { Vektor(5.0, 2.0, 7.0), Vektor(1.0, 1.0, 1.0), Vektor(-1.3, -2.3, 4.1), _ Vektor(5.2, -1.3, 1.4), Vektor(5.2, 1.3, 1.8) } ScreenRes 640, 480, 4 Width 80, 30 Dim i As Integer For i = LBound(d) To UBound(d) Print KKleinste(d(), 1 + i - LBound(d)) Next i For i = LBound(q) To UBound(q) Print KKleinste(q(), 1 + i - LBound(q)) Next i For i = LBound(v) To UBound(v) Print KKleinste(v(), 1 + i - LBound(v)).toString() Next i Print "Unterbereiche" Print KKleinste(d(), 1, 1, 2) Print KKleinste(q(), 2, 1, 3) Print KKleinste(v(), 2, 1, 3).toString() Sleep