#include "stdafx.h"
#include <iostream>
using namespace std;
int Func(int *A, int nSize)
{
if (NULL == A || nSize <= 0)
{
return -1;
}
int count = 0;
int pos = -1;
for (int i = 0; i < nSize; i++)
{
if (-1 == pos && A[i] == 0)
{
pos = i;
count++;
}
else if (A[i] == 0)
{
count++;
}
else
{
for (int j = 0; j < count; j++)
{
A[i - j - 1] = A[i - j];
}
}
}
for (int i = count; i > 0; i--)
{
A[nSize - i] = 0;
}
return pos;
}
int _tmain(int argc, _TCHAR* argv[])
{
int A[] = {6 ,0 ,3, 4, 0, 5, 9, 6, 4, 6, 5, 8, 0, 0};
int nSize = sizeof(A)/sizeof(A[0]);
cout<<"before: ";
for (int i = 0; i < nSize; i++)
{
cout<<A[i]<<" ";
}
int pos = Func(A, nSize);
cout<<endl<<"after: ";
for (int i = 0; i < nSize; i++)
{
cout<<A[i]<<" ";
}
cout<<endl<<"原数组第一个0元素的下标为: "<<pos<<endl;
cout<<endl;
system("pause");
return 0;
}