Last night I used std :: vector for my work, and this question popped up in my head: how does a vector give random access?
I tried to learn the code, but was unsuccessful. Can someone give some pointers?
Thanks Arun
A vector uses adjacent memory at the bottom, so it gives random access just like an array: it knows the starting address and size of the elements and does some math pointer.
Of course, here are a few pointers:
int *x, *y;
, vector . ([]), .
vector
[]
[*]... , O (1) ( ) .
( ) (. ). , , 2, n- , (2 * n) (4 * n)-th ...
, , N O (N). , , - .
[*] , . -?
, 1,5 , , .
Source: https://habr.com/ru/post/1722612/More articles:Cannot force log4net to output anything when using NHibernate - nhibernateApplication Time VB6 - timeCreating a C # object is much slower than calling a constructor - performanceCatch the text before inserting it into the text box - c #Внедрить XML в node с помощью строки - stringКак поделиться изображением между проектами в Microsoft SQL Server Reporting Services 2005? - sql-server-2005Вывод WWW-аутентификации - httpСкрытие столбцов в таблице данных Microsoft Access 2007 с помощью VBA - vbaThe pains of creating a global application - web-applicationsHow do I know when my program crashed for the last time? - designAll Articles