SelectElement()

Syntax

Result = SelectElement(LinkedList(), Position)
Description
Change the current list element to the element at the specified position. This is very useful if you want to jump to a specific position in the list without using an own loop for this.

Parameters

LinkedList() The name of your linked-list variable, created with the NewList function. You must include the brackets after the list name.
Position The position to move to in the list, considering that the first item in the list is at position 0, the next is at 1 and so on. You must make sure that you do not specify a position that is outside of the number of elements in the list!

Return value

Returns the data address of the selected element if successful or zero if the position is out of range.

Remarks

As linked-lists don't use an index internally, this function will jump compulsory to every element in the list until the target position is reached which will take time if the list is large. If a faster method is needed, ChangeCurrentElement() should be used.

Example

  NewList mylist.l()

  AddElement(mylist()) : mylist() = 23
  AddElement(mylist()) : mylist() = 56
  AddElement(mylist()) : mylist() = 12
  AddElement(mylist()) : mylist() = 73

  SelectElement(mylist(), 0)
  MessageRequester("Position", "At position 0, the value is "+Str(mylist()),0)

  SelectElement(mylist(), 2)
  MessageRequester("Position", "At position 2, the value is "+Str(mylist()),0)

  SelectElement(mylist(), 1)
  MessageRequester("Position", "At position 1, the value is "+Str(mylist()),0)

  SelectElement(mylist(), 3)
  MessageRequester("Position", "At position 3, the value is "+Str(mylist()),0)

See Also

ChangeCurrentElement()

Supported OS

All

<- ResetList() - LinkedList Index - SplitList() ->