How to get an Enumerator
to an item in a -Sorted- dictionary using key?
Note:GetEnumerator()
gets an Enumerator
to first element..
But I need to get an Enumerator
to the element with a given key in order to gain access to next elements using MoveNext()
for example...
Edit: Or a way to access next elements...
Edit: I prefer a const time method...
Thanks
std::next in C++. std::next returns an iterator pointing to the element after being advanced by certain no. of positions. It is defined inside the header file . It does not modify its arguments and returns a copy of the argument advanced by the specified amount. If it is a random-access iterator, the function uses just once operator + or ...
The short, long, signed and unsigned keywords are type modifiers that alter the meaning of a base data type to yield a new type. The return keyword terminates the function and returns the value. This function func () returns 5 to the calling function.
Keywords in C Programming; auto: break: case: char: const: continue: default: do: double: else: enum: extern: float: for: goto: if: int: long: register: return: short: signed: sizeof: static: struct: switch: typedef: union: unsigned: void: volatile: while
The extern keyword declares that a variable or a function has external linkage outside of the file it is declared. To learn more, visit C storage type. There are three types of loops in C programming. The for loop is written in C programming using the keyword for.
var enumerator = dictionary.Keys.SkipWhile(k => k != myKey)
Where myKey is the key you're looking for. And you can use the OrderBy extension method if you want to have the keys sorted.
Edit: You can't do it in constant with Dictionary/SortedDictionary. Why not implement your own binary search tree (like SortedDictionary is) and you will have O(log n) time lookup and O(1) time .next()
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With