Omnimaga
Calculator Community => TI Calculators => TI-BASIC => Topic started by: collechess on June 02, 2011, 08:40:37 pm
-
Is it possible to remove an element from a list so the following elements shift to fill in where it was? If so, how?
-
I don't believe there is a built-in way of doing so. However, one possible way of doing so would be if you created an intermediate list (one element smaller), and copied all of the cells before and all of the cells after into it.
-
Yeah, unfortunately there's no way do do it automatically. You could get by with something like this, but it's a bit slow for long lists.
Initial list (numbers 1 to 5):
:{1,2,3,4,5→L₁
Remove third element (leaves {1,2,4,5}):
:seq(L₁(I+(I≥3),I,1,4→L₁
-
Off the top of my head...
0 ->L1(element # you want to delete)
For I,1,dimL1
If L1(I)=0 and I!= dimL1
Then
L1(I+1)->L1(I)
0->L1(I+1)
End
End
If the elements don't need to be kept in order it's a bit easier,and I can post code for that as well. The above should work for what you are asking though. I haven't done any BASIC in a while so test it first. :)
Oh, and != means the not equal operator.