Author Topic: Remove an Element from a List?  (Read 2797 times)

0 Members and 1 Guest are viewing this topic.

Offline collechess

  • LV3 Member (Next: 100)
  • ***
  • Posts: 93
  • Rating: +22/-2
    • View Profile
Remove an Element from a List?
« 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?

Ashbad

  • Guest
Re: Remove an Element from a List?
« Reply #1 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.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Remove an Element from a List?
« Reply #2 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₁
« Last Edit: June 02, 2011, 09:00:21 pm by Deep Thought »




Offline TIfanx1999

  • ಠ_ಠ ( ͡° ͜ʖ ͡°)
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 6173
  • Rating: +191/-9
    • View Profile
Re: Remove an Element from a List?
« Reply #3 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.