How to search through an array of structs?

I’m trying to create a system that finds the correct item type and increases its quantity. Currently I have an array of structs, each containing both a class and a quantity. How can I search for one struct element, without knowing the value of the other? I cannot use a dictionary, as the items must be sorted.

Meh… you have to loop through…

I was just looking for a more efficient method, as that would require three loops: one to calculate the distances between the items and the player, one to loop through the inventory array, and then one to loop through each struct.

Does it have to be sorted?

Yes. I am attempting to recreate Breath of The Wild’s inventory. There can only be one slot for each item type, but the items are placed in the same order in which they were picked up.

You could a dictionary to store them, but keep the order in another array :slight_smile:

Like this ( @jmancoder1 ):

image

What about trying to implement a linked list?