Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ - walking on Set (from STL)

I was wondering if walking on Set (from STL) is very costly? I need sorted array and that's the only reason I used Set. Should I create my own sorted list or walking on Set is "ok"?

like image 715
user3613919 Avatar asked Dec 18 '25 05:12

user3613919


1 Answers

No, it is not costly (asymptotically). According to C++ standard it's done in linear time because each step takes constant time (amortized).

Although walking through actual sorted array (e.g std::vector or plain C array) may be a little bit faster due to lower constant.

like image 79
Qumeric Avatar answered Dec 20 '25 21:12

Qumeric



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!