Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void replaceInArray(ref int[] arr, int find, int replace)
- {
- int[] newArr = getIndices(arr, find);
- for(int i = 0; i < newArr.Length - 1; i++)
- {
- arr[newArr[i]] = replace;
- }
- }
- public static int[] getIndices(int[] arr, int find)
- {
- int[] newArr = new int[arr.Length - 1];
- int count = 0;
- for (int i = 0; i < arr.Length; i++)
- {
- if (arr[i] == find)
- {
- newArr[i] = i;
- count++;
- }
- }
- int[] indexArr = new int[count];
- for(int i = 0; i < indexArr.Length; i++)
- {
- indexArr[i] = newArr[i];
- }
- return indexArr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement