UniqueDynArray

    Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

    Unsere Datenschutzerklärung wurde aktualisiert. Mit der Nutzung unseres Forums akzeptierst Du unsere Datenschutzerklärung. Du bestätigst zudem, dass Du mindestens 16 Jahre alt bist.

    • UniqueDynArray

      Noch eine kleine Funktion wie MultiIndexOf, aber nur für dynamische Arrays.

      Quellcode

      1. Declare int wuerfel[25,25]
      2. Declare string s
      3. $I c:\XProfan\Projekte\Include\MultiIndexOf.inc
      4. $I c:\XProfan\Projekte\Include\UniqueDynArray.inc
      5. cls
      6. wuerfel[3,8] = 17
      7. wuerfel[12,12] = 17
      8. wuerfel[17, 3] = 17
      9. wuerfel[24,25] = 17
      10. Print "wuerfel[3,8] = 17"
      11. Print "wuerfel[12,12] = 17"
      12. Print "wuerfel[17, 3] = 17"
      13. Print "wuerfel[24,25] = 17"
      14. Print " "
      15. s = MultiIndexOf( wuerfel[], 17,-1 ) : print s $ " -- Len: " $ Len(s,";")
      16. Print " "
      17. s = MultiIndexOf( wuerfel[], 17, 1 ) : print s $ " -- Len: " $ Len(s,";")
      18. Print " "
      19. s = MultiIndexOf( wuerfel[], 17, 2 ) : print s $ " -- Len: " $ Len(s,";")
      20. Print " "
      21. s = MultiIndexOf( wuerfel[], 17, 3 ) : print s $ " -- Len: " $ Len(s,";")
      22. Print "\nLastIndexOf:"
      23. s = MultiIndexOf( wuerfel[], 17,-1 ) : print SubStr$(s, Len(s,";"), ";") $ " -- Idx: " $ Len(s,";")
      24. waitinput
      25. Var string arr[] = "Alfa","Alfa-Echo","Bravo","Charlie","Charlie-Hotel","Delta","Echo","Echo","Echo","Foxtrot","Golf","Hotel","India",\
      26. "Juliett","Kilo","Lima","Mike","November","Oscar","Oscar-Echo","Papa","Quebec","Romeo","Sierra","Sierra-Sierra","Tango",\
      27. "Uniform","Uniform-Echo","Victor","Whiskey","X-Ray","Yankee","Zulu"
      28. Print "\nfinde ECHO vor Unique():"
      29. s = MultiIndexOf( arr[], "Echo", -1 ) : print s $ " = ECHO"
      30. UniqueDynArray( arr[] )
      31. Print "\nfinde ECHO nach Unique():"
      32. s = MultiIndexOf( arr[], "Echo", -1 ) : print s $ " = ECHO"
      33. waitend
      Alles anzeigen


      Quellcode: UniqueDynArray.inc

      1. ' Autor: Michael Wodrich
      2. ' XProfan X3.1
      3. Proc UniqueDynArray
      4. Declare string PT, int PC : PT = PType$(1) : PC = %PCount
      5. Declare int a,b, max_a
      6. Var int sorted = 1
      7. Var int dele = 0
      8. Select PT
      9. CaseOf "%[]" // Integer (Int)
      10. Parameters int arr_I[]
      11. max_a = SizeOf(arr_I[]) - 1
      12. If max_a > 0
      13. a = 0
      14. While (sorted = 1) and (a < max_a)
      15. Case arr_I[a] > arr_I[a + 1] : sorted = 0
      16. Inc a
      17. EndWhile
      18. If sorted
      19. a = 0
      20. Repeat
      21. WhileLoop a + 1, max_a
      22. If arr_I[a] == arr_I[&loop]
      23. Inc dele
      24. Else
      25. If dele
      26. ArrDel arr_I[], a + 1, dele
      27. Dec max_a, dele
      28. Clear dele
      29. EndIf
      30. BREAK
      31. EndIf
      32. EndWhile
      33. Inc a
      34. Until a >= max_a
      35. Else
      36. a = 0
      37. Repeat
      38. WhileLoop max_a, a + 1, -1
      39. If arr_I[a] == arr_I[&loop]
      40. ArrDel arr_I[], &loop, 1
      41. Dec max_a
      42. EndIf
      43. EndWhile
      44. Inc a
      45. Until a >= max_a
      46. EndIf
      47. EndIf
      48. CaseOf "&[]" // Longint (Long), Handle (Pointer)
      49. Parameters long arr_L[]
      50. max_a = SizeOf(arr_L[]) - 1
      51. If max_a > 0
      52. a = 0 : While (sorted = 1) and (a < max_a) : Case arr_L[a] > arr_L[a + 1] : sorted = 0 : Inc a : EndWhile
      53. If sorted
      54. a = 0 : Repeat : WhileLoop a + 1, max_a : If arr_L[a] == arr_L[&loop] : Inc dele : Else : If dele : ArrDel arr_L[], a + 1, dele : Dec max_a, dele : Clear dele : EndIf : BREAK : EndIf : EndWhile : Inc a : Until a >= max_a
      55. Else
      56. a = 0 : Repeat : WhileLoop max_a, a + 1, -1 : If arr_L[a] == arr_L[&loop] : ArrDel arr_L[], &loop, 1 : Dec max_a : EndIf : EndWhile : Inc a : Until a >= max_a
      57. EndIf
      58. EndIf
      59. CaseOf "Q[]" // Quadint (Quad)
      60. Parameters quad arr_Q[]
      61. max_a = SizeOf(arr_Q[]) - 1
      62. If max_a > 0
      63. a = 0 : While (sorted = 1) and (a < max_a) : Case arr_Q[a] > arr_Q[a + 1] : sorted = 0 : Inc a : EndWhile
      64. If sorted
      65. a = 0 : Repeat : WhileLoop a + 1, max_a : If arr_Q[a] == arr_Q[&loop] : Inc dele : Else : If dele : ArrDel arr_Q[], a + 1, dele : Dec max_a, dele : Clear dele : EndIf : BREAK : EndIf : EndWhile : Inc a : Until a >= max_a
      66. Else
      67. a = 0 : Repeat : WhileLoop max_a, a + 1, -1 : If arr_Q[a] == arr_Q[&loop] : ArrDel arr_Q[], &loop, 1 : Dec max_a : EndIf : EndWhile : Inc a : Until a >= max_a
      68. EndIf
      69. EndIf
      70. CaseOf "![]" // Float (Double)
      71. Parameters float arr_F[]
      72. max_a = SizeOf(arr_F[]) - 1
      73. If max_a > 0
      74. a = 0 : While (sorted = 1) and (a < max_a) : Case arr_F[a] > arr_F[a + 1] : sorted = 0 : Inc a : EndWhile
      75. If sorted
      76. a = 0 : Repeat : WhileLoop a + 1, max_a : If arr_F[a] == arr_F[&loop] : Inc dele : Else : If dele : ArrDel arr_F[], a + 1, dele : Dec max_a, dele : Clear dele : EndIf : BREAK : EndIf : EndWhile : Inc a : Until a >= max_a
      77. Else
      78. a = 0 : Repeat : WhileLoop max_a, a + 1, -1 : If arr_F[a] == arr_F[&loop] : ArrDel arr_F[], &loop, 1 : Dec max_a : EndIf : EndWhile : Inc a : Until a >= max_a
      79. EndIf
      80. EndIf
      81. CaseOf "S[]" // Single
      82. Parameters single arr_S[]
      83. max_a = SizeOf(arr_S[]) - 1
      84. If max_a > 0
      85. a = 0 : While (sorted = 1) and (a < max_a) : Case arr_S[a] > arr_S[a + 1] : sorted = 0 : Inc a : EndWhile
      86. If sorted
      87. a = 0 : Repeat : WhileLoop a + 1, max_a : If arr_S[a] == arr_S[&loop] : Inc dele : Else : If dele : ArrDel arr_S[], a + 1, dele : Dec max_a, dele : Clear dele : EndIf : BREAK : EndIf : EndWhile : Inc a : Until a >= max_a
      88. Else
      89. a = 0 : Repeat : WhileLoop max_a, a + 1, -1 : If arr_S[a] == arr_S[&loop] : ArrDel arr_S[], &loop, 1 : Dec max_a : EndIf : EndWhile : Inc a : Until a >= max_a
      90. EndIf
      91. EndIf
      92. CaseOf "$[]" // String
      93. Parameters string arr_Str[]
      94. max_a = SizeOf(arr_Str[]) - 1
      95. If max_a > 0
      96. a = 0 : While (sorted = 1) and (a < max_a) : Case arr_Str[a] > arr_Str[a + 1] : sorted = 0 : Inc a : EndWhile
      97. If sorted
      98. a = 0 : Repeat : WhileLoop a + 1, max_a : If arr_Str[a] == arr_Str[&loop] : Inc dele : Else : If dele : ArrDel arr_Str[], a + 1, dele : Dec max_a, dele : Clear dele : EndIf : BREAK : EndIf : EndWhile : Inc a : Until a >= max_a
      99. Else
      100. a = 0 : Repeat : WhileLoop max_a, a + 1, -1 : If arr_Str[a] == arr_Str[&loop] : ArrDel arr_Str[], &loop, 1 : Dec max_a : EndIf : EndWhile : Inc a : Until a >= max_a
      101. EndIf
      102. EndIf
      103. CaseOf "W[]", "µ[]" // Widestring (Wide)
      104. Parameters wide arr_W[]
      105. max_a = SizeOf(arr_W[]) - 1
      106. If max_a > 0
      107. a = 0 : While (sorted = 1) and (a < max_a) : Case arr_W[a] > arr_W[a + 1] : sorted = 0 : Inc a : EndWhile
      108. If sorted
      109. a = 0 : Repeat : WhileLoop a + 1, max_a : If arr_W[a] == arr_W[&loop] : Inc dele : Else : If dele : ArrDel arr_W[], a + 1, dele : Dec max_a, dele : Clear dele : EndIf : BREAK : EndIf : EndWhile : Inc a : Until a >= max_a
      110. Else
      111. a = 0 : Repeat : WhileLoop max_a, a + 1, -1 : If arr_W[a] == arr_W[&loop] : ArrDel arr_W[], &loop, 1 : Dec max_a : EndIf : EndWhile : Inc a : Until a >= max_a
      112. EndIf
      113. EndIf
      114. Otherwise
      115. Error 999,"nur mit dyn. Arrays einsetzen"
      116. EndSelect
      117. EndProc
      Alles anzeigen
      Programmieren, das spannendste Detektivspiel der Welt.