How do I combine inventory slot items?

The way i imagine it is, in each slot there is stored an struct with the data of the item, and maybe an index of which slot is and store it within an array, this is cleaner if you create it dynamically on construct. When you click the slot, you check for a buffer variable where the item info goes, if it is not valid or empty, you store the item info of your first item, then on your second click you check if the first buffer should be valid or not empty, then you do the math of the item combining, once all is done you clear both buffers so you can do it again.