I'm trying to implement insertion sort in TI-BASIC on the TI-84 and have nearly been successful. My solution sorts all but the first element of the list. In order to work properly, I believe this line:
While C>1 and L1(C)>V
needs to be
While C>0 and L1(C)>V
However this creates an error because apparently TI-BASIC is checking L1(0)
even though we are exiting the loop before getting there.
Could someone please explain how to avoid this problem and make the code work?
This is my code:
0->dim(L1
randIntNoRep(1,10,10)->L1
For(I,2,10)
L1(I)->V
I-1->C
While C>1 and L1(C)>V
L1(C)->L1(C+1)
C-1->C
End
V->L1(C+1)
End
Disp L1