You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jul 10, 2024. It is now read-only.
void moveZeroesToEnd(std::vector& nums) {
int nonZeroIndex = 0;
// Iterate through the vector and move non-zero elements to the beginning
for (int num : nums) {
if (num != 0) {
nums[nonZeroIndex++] = num;
}
}
// Fill the remaining elements with zeroes
while (nonZeroIndex < nums.size()) {
nums[nonZeroIndex++] = 0;
}
moveZeroesToEnd(nums);
std::cout << "Array after moving zeroes to the end:" << std::endl;
for (int num : nums) {
std::cout << num << " ";
}
std::cout << std::endl;
return 0;
}
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Description
Write a program to move all zeroes to end of array
The text was updated successfully, but these errors were encountered: