Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!ns-mx!piquet.cipl.uiowa.edu!wolf From: wolf@piquet.cipl.uiowa.edu (Michael J. Wolf) Newsgroups: comp.sys.mac.programmer Subject: Re: How to best do a linked list on Mac Message-ID: <6455@ns-mx.uiowa.edu> Date: 13 Jun 91 12:43:25 GMT References: <1991Jun10.002416.5656@gn.ecn.purdue.edu> <14026@goofy.Apple.COM> Sender: news@ns-mx.uiowa.edu Organization: Cardiovascular Image Processing Laboratory, U of Iowa Lines: 33 In article <14026@goofy.Apple.COM> casseres@apple.com (David Casseres) writes: >In article , >francis@zaphod.uchicago.edu (Francis Stracke) writes: > >> My favorite solution is to declare an array type, then allocate a >> handle to such an array, and resize it dynamically. >> >> That way you can do it with only one handle (though you may want to >> have an array of handles, if your records are large), and you can >> index into the array rather than searching the list. > >This works fine but it isn't a linked list -- it's a dynamically sized >array. It's good as long as all you will do is add elements at the end >or remove them from the end, but it doesn't allow you to add elements >in the middle, or remove them from the middle and reclaim their storage >space. > >David Casseres If you wanted to not have empty sapces in the 'array' and wanted to do true insertions so that your 'array' is always progressive, you could have your insert routine use a temphandle, set that handle to point to the array item number where you wish to insert, then do a HandtoHand copy, resize the List handle to add another item, then add the item at the insertion point (just write over the original items data) then do a HandTohand copy from the temp handle back to the List handle. This would be virtually the same for deleting items also. In this scheme you would not need to have a next or previous pointer since the array is always progressive. Just a thought... Michael