C++ check array for duplicates and replace them -


i have array full of values, array can not contain duplicate values. duplicate value add 1 value. here code have far, im still getting duplicates. (randarray values located).

for (int = 0; < sizeof(randarray) - 1; i++) {     (int j = sizeof(randarray); j == 0; j--) {         if (randarray[i] == randarray[j]) {             randarray[i] == randarray[i] + 1;         }     } } 

you have typo when incrementing duplicate:

     randarray[i] = randarray[i] + 1; // not == 

also, increment might create duplicate. if it's item comes afterwards there's no problem. array not sorted, might not catch such new duplicate of value passed.

therefore might need several passes:

 bool wasaninc;  {       wasaninc=false;       ...           ...               ... // if there increment, set wasaninc true   } while (wasaninc); 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -