Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: collechess on June 02, 2011, 08:40:37 pm

Title: Remove an Element from a List?
Post 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?
Title: Re: Remove an Element from a List?
Post by: Ashbad on June 02, 2011, 08:50:17 pm
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.
Title: Re: Remove an Element from a List?
Post by: Deep Toaster on June 02, 2011, 08:56:58 pm
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):

Code: (TI-BASIC) [Select]
:{1,2,3,4,5→L₁
Remove third element (leaves {1,2,4,5}):

Code: (TI-BASIC) [Select]
:seq(L₁(I+(I≥3),I,1,4→L₁
Title: Re: Remove an Element from a List?
Post by: TIfanx1999 on June 02, 2011, 09:01:27 pm
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.