Computer Science Canada

Deleting elements in an array

Author:  tum_twish [ Thu Jun 05, 2003 10:35 am ]
Post subject:  Deleting elements in an array

Is it possible to delete an element (parition)of an array (ie. make it no value) given the index (subscript) of the element?

Author:  Martin [ Thu Jun 05, 2003 10:49 am ]
Post subject: 

Nope. Just set it to a flag value that you know isn't going to be used, or use linked lists

Author:  tum_twish [ Thu Jun 05, 2003 10:53 am ]
Post subject: 

what r linked lists?

Author:  Martin [ Thu Jun 05, 2003 10:57 am ]
Post subject: 

It's a really efficient way to store data.

Basically you have a pointer to the first memory location of a record, and then each subsequent record has a pointer to the next one in line

code:
type list :
   record
     x,y : int %just to make the record hold something
     next : ^list %Pointer to the next node
   end record


you then have a variable
code:
var first : ^list
and set that = to nil. Then, whenever you want to add a new element to the list, you allocate a new memory location for a new node, and add that to the end of the node. I'll write a tutorial on this later.

Author:  Blade [ Thu Jun 05, 2003 11:19 am ]
Post subject: 

i kinda thought he was talking about flexible arrays..

Author:  PaddyLong [ Thu Jun 05, 2003 4:17 pm ]
Post subject: 

flexible arrays wouldn't really work... they just resize the array, not reset it...


: