I have no idea what you are trying to express with your [x][x] type of syntax. Is that a two dimensional array, or some other thing that you are making up for the purposes of psudocode? And are you trying to do a comparison in the if statement, or is that an assignment? And in your for loop, why are you trying to increment z in the initializer? I know you said it wasn't valid c++ code, but come on. How is anyone supposed to understand what you mean without reading your mind?

The crows maintain that a single crow could destroy the heavens. Doubtless this is so. But it proves nothing against the heavens, for the heavens signify simply: the impossibility of crows.

I have no idea what you are trying to express with your [x][x] type of syntax. Is that a two dimensional array, or some other thing that you are making up for the purposes of psudocode? And are you trying to do a comparison in the if statement, or is that an assignment? And in your for loop, why are you trying to increment z in the initializer? I know you said it wasn't valid c++ code, but come on. How is anyone supposed to understand what you mean without reading your mind?

id is an int variable of a class - a[0].id thru a[n].id is alrdy filled with product ids and tmp[0][0].id is initialized to a[0]...what i want to do is check to see if each product id is equal in the array if it is equal, the loop would store each equal value in tmp[0][1].id tmp[0][2].id .. etc.. and another diff id would go in tmp[1][0].id tmp[1][1].id ..

I assume that the values that are not set are already defaulted to some number (like 0 or -1) that cannot be an actual value for the id.

If that is the case, then for each id, you'd start at tmp[0][0]. If it matches, then you loop through tmp[0][j] until it is not used (it has that initial value 0 or -1) and then place it there. If tmp[0][0] doesn't match, you move on to tmp[1][0] and repeat. Continue until tmp[i][0] has the inital value (0 or -1), meaning it hasn't been used yet. At that point set it to the current value.

That algorithm can be done in two simple loops, where you have a done variable that allows you to break out of the two loops when you actually findthe right location. A third loop can be used to cycle through the a array.

I assume that the values that are not set are already defaulted to some number (like 0 or -1) that cannot be an actual value for the id.

If that is the case, then for each id, you'd start at tmp[0][0]. If it matches, then you loop through tmp[0][j] until it is not used (it has that initial value 0 or -1) and then place it there. If tmp[0][0] doesn't match, you move on to tmp[1][0] and repeat. Continue until tmp[i][0] has the inital value (0 or -1), meaning it hasn't been used yet. At that point set it to the current value.

That algorithm can be done in two simple loops, where you have a done variable that allows you to break out of the two loops when you actually findthe right location. A third loop can be used to cycle through the a array.

i wrote it but something is working incorrectly it stores again at diff locations

I didn't change your code, I just modified the indentation so that you could see what was happening. I'm not sure how that code gave you that output (what does the input look like?), but as you can see if you follow the code, it won't follow the algorithm the way you want it to.

The first problem I see is that when you find the location to store the variable, you call break, but that only breaks out of one loop. You need a separate variable that you set to false at the beginning of the outer loop, and then set to true when you've stored the current value from STORE1. You then need to check that variable in both inner loops and break if it is true so that you start again with the next value from STORE1.

The second problem is the if statement in between the second and third loop. I don't think it ends where you want it to, since all the code that could add the value is inside there and will never get called if you don't have a match already in there. Maybe moving the closing brace for that and using an else might help.

I didn't change your code, I just modified the indentation so that you could see what was happening. I'm not sure how that code gave you that output (what does the input look like?), but as you can see if you follow the code, it won't follow the algorithm the way you want it to.

The first problem I see is that when you find the location to store the variable, you call break, but that only breaks out of one loop. You need a separate variable that you set to false at the beginning of the outer loop, and then set to true when you've stored the current value from STORE1. You then need to check that variable in both inner loops and break if it is true so that you start again with the next value from STORE1.

The second problem is the if statement in between the second and third loop. I don't think it ends where you want it to, since all the code that could add the value is inside there and will never get called if you don't have a match already in there. Maybe moving the closing brace for that and using an else might help.