Trouble with: Procedure RemoveListDuplicates()
Sorry having BrainFog :
Code: Select all
;EnableExplicit
Global NewList WordsList.s() , NewList Index_List.s()
; Directly add words to the list using AddElement
AddElement(WordsList())
WordsList() = "Apple"
AddElement(WordsList())
WordsList() = "apple"
AddElement(WordsList())
WordsList() = "Apple"
AddElement(WordsList())
WordsList() = "Banana"
AddElement(WordsList())
WordsList() = "Banana"
AddElement(WordsList())
WordsList() = "banana"
AddElement(WordsList())
WordsList() = "apple" ; Intentional case-insensitive duplicate
AddElement(WordsList())
WordsList() = "Carrot"
AddElement(WordsList())
WordsList() = "Banana" ; Exact duplicate
; Sort the list to facilitate duplicate removal
SortList(WordsList(), #PB_Sort_Ascending | #PB_Sort_NoCase)
; Function to remove duplicates from a sorted list
Procedure RemoveListDuplicates()
If ListSize(WordsList()) > 0 ; Only process if there is at least one element
Define previousLine.s = "zzzzzzzz"
ForEach WordsList()
If previousLine = WordsList()
DeleteElement(WordsList(), ListIndex(WordsList())) ; Remove the duplicate element
NextElement(WordsList())
EndIf
If previousLine <> WordsList() ; Update previous line
Debug "WordsList() = " + ListSize(WordsList())
Debug "ListSize() = " + ListSize(Index_List())
AddElement(Index_List())
Index_List() = WordsList()
EndIf
Next
EndIf
EndProcedure
; Remove duplicates
RemoveListDuplicates()
; Function to print the list
Procedure PrintWordsList()
ForEach WordsList()
Debug "Word: " + WordsList()
Next
ForEach Index_List()
Debug "Word: " + Index_List()
Next
EndProcedure
; Print the words in the list
PrintWordsList()
; Clean up
FreeList(WordsList())
MessageRequester("End of Program", "The program has completed execution.")



