Data Structure Array: Move all zeroes to end of array
2014-04-10 05:47
323 查看
http://www.geeksforgeeks.org/move-zeroes-end-array/
#include <iostream> #include <vector> #include <algorithm> #include <queue> #include <stack> #include <string> #include <fstream> #include <map> #include <set> using namespace std; void movezero(int arr[], int n) { int c = 0; for (int i = 0; i < n; i++) { if (arr[i] == 0) continue; arr[c++] = arr[i]; } for (int i = c; i < n; i++) arr[i] = 0; } int main() { int arr[12] = {1, 9, 8, 4, 0, 0, 2, 7, 0, 6, 0, 9}; movezero(arr, 12); for (int i = 0; i < 12; i++) cout << arr[i] << " "; return 0; }
相关文章推荐
- 把零移动到数组的一端 Move all zeroes to end of array
- Move all zeroes to end of array
- Move all zeroes to end of array
- Given an array nums, write a function to move all 0's to the end of it while maintaining the relativ
- Data Structure Array: Maximum of all subarrays of size k
- Data Structure Array: Given an array of of size n and a number k, find all elements that appear more than n/k times
- iOS: NSFileHandle的方法readDataToEndOfFile
- vim separate with . and replace all to end of line
- Given a list of presentations with begin and end time that all need to use a conference room.
- The minimum number of elements to reach the end of an array
- EndOfStreamException: Unable to read additional data from client sessionid 0x0, likely client has cl
- End of the "Road to DataStage Certification" D
- Data Structure Array: Largest subarray with equal number of 0s and 1s
- Data Structure Array: Find the Increasing subsequence of length three with maximum product
- how to get Class of primitive datatypes array . Class.forName(int[]) throws exception
- Loading Data when the User Scrolls to the End of a List in Windows Phone 7
- Select n numbers from 1 to m with all of array 'all' and none of array 'none'
- Unable to determine the principal end of an association between the types '***. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.
- Data Structure Linked List: Write a function to get the intersection point of two Linked Lists.
- No Datastore Session bound to thread, and configuration does not allow creation of non-transactional