Trista N
Trista N

Reputation: 423

C++ List Index Query

For the STL data structure, list, does the index begin at 0 or 1? The online material regarding this is confusing..

Upvotes: 1

Views: 1782

Answers (2)

Jerry Coffin
Jerry Coffin

Reputation: 490468

std::list doesn't really have/use any integer index. When you need to specify a position (or get a position, such as with a search algorithm) it'll be in terms of an iterator, not an index.

Upvotes: 0

Rohit Vipin Mathews
Rohit Vipin Mathews

Reputation: 11787

It doesnt have an index. It is implemented as doubly linked list. Only arrays have index. If you need index use vector or deque. they lack direct access to the elements by their position as there is no random access iterator for list.

Read this for more information on lists.

Upvotes: 2

Related Questions