I have an array of integers that represent their own strings.
I know there are simple ways to sort integer arrays, but I needed to make it so that the integers retain their correspondence to the strings.
Here is my current code:
var i = 0
var highestValueObjectInArray = 0
for object in createTimerData.speechTimeStamps {
if object > highestValueObjectInArray {
highestValueObjectInArray = object
}
}
while i + 1 < createTimerData.speechTimeStamps.count {
if createTimerData.speechTimeStamps[i] < createTimerData.speechTimeStamps[i + 1] {
let TS2 = createTimerData.speechTimeStamps[i + 1]
let TSS2 = createTimerData.speechText[i + 1]
createTimerData.speechTimeStamps.remove(at: i + 1)
createTimerData.speechTimeStamps.insert(TS2, at: i)
createTimerData.speechText.remove(at: i + 1)
createTimerData.speechText.insert(TSS2, at: i)
}
i += 1
if i+1 >= createTimerData.speechTimeStamps.count {
var lastItem = highestValueObjectInArray + 1
var inDescendingOrder = true
for object in createTimerData.speechTimeStamps {
if object < lastItem {} else { inDescendingOrder = false }
lastItem = object
}
if inDescendingOrder == false {
i = 0
}
}
}
It is very slow and not very efficient so when it sorts large arrays it takes a large amount of time. Is there a way I have overlooked, or a way that is more efficient.
Any help would be much appreciated, thanks.