Talk:Search a list: Difference between revisions

You may be right (I may be crazy)
(What does it mean to "inately support access at an index"?)
(You may be right (I may be crazy))
Line 3:
:: What does it mean to "inately support access at an index"? Of course for any sequence you can define access at index ''n'' by just starting at the first element and then going to the next element ''n'' times (this gives zero-based indexing, of course). Note that in Lisp, the function <code>nth</code> does exactly that for lists. However, for a real array, accessing the element at index ''n'' is a constant-time operation. Therefore, would you say that Lisp lists (as opposed to Lisp vectors) "inately support access at an index"? And if so, what would a sequence look like that doesn't do so?
:: Also, does it really matter for the task that you can access the element through that index? After all, the indexing itself isn't demonstrated. I guess the question comes down to what the task is actually intended to demonstrate. --[[User:Ce|Ce]] 16:47, 26 November 2008 (UTC)
:::You may be right. The collection type is obviously not the focus of this task, so it shouldn't be restricted if collections other than arrays fit the bill. It shouldn't be restricted to "haystack[i]" because first, some languages don't use that syntax and second, some collections which do support indexing do it through functions and methods (like nth from List or ArrayList.get() from Java). It should work for collections where if I run this function and get an index, then add an element to the "end" of the collection (that is, add an element to an end of the collection so that its index is greater than the index I got when I ran the function), then run the function again with the same arguments, I should get the same number. If that sounds like an OK specification, then which collections match it? --[[User:Mwn3d|Mwn3d]] 16:59, 26 November 2008 (UTC)
Anonymous user