怎么用两个循环删除数组中的相同元素

如何用两个循环删除数组中的相同元素
将一组元素输入数组中,不能使用额外的空间去建立其他容器去储藏这组元素,也就是说空间复杂度是O(1).这组元素在删除重复元素后其顺序不能改变,也就是说不能先排序然后删除元素。我写了一下的代码,但是使用了三个for loop,现在想请大家看看能不能改成两个循环。谢谢啦

#include <iostream>  
#include <fstream>  
using namespace std;  
void removeDuip(int *arr,int &cnt);
int complexity=0;  
int main()  
{  
    int arr[200]={0}; 
    string filename;
cout<<"enter file name:";
getline(cin,filename);
    ifstream infile(filename.c_str());  
    int count = 0;  
    while(!infile.eof())  
    {  
        infile>>arr[count];  
        ++count;  
    }  
    infile.close();

//int size=sizeof(arr)/sizeof(int);
  
    for ( int j= 0; j < count; ++j)  
        cout<<arr[j]<<" ";  
cout<<"the array size is "<<count<<endl;


 int cnt=count;
 removeDuip(arr,cnt);
 
for ( int j= 0; j < cnt; ++j)  
        cout<<arr[j]<<" ";  
  cout<<"the final size is"<<cnt<<endl; 
  cout<<"the comparsions are "<<complexity<<endl;
    return 0;  
}  

void removeDuip(int *arr,int &cnt){
   for(int i=0;i<cnt;++i){ //search every element from the firs one
    // int changePosition;
     for(int j=i+1;j<cnt;++j){//use this element to compare 
       if(arr[j]==arr[i]){
         for(int k=j+1;k<cnt;++k){
           arr[k-1]=arr[k];//shift element from right to left when there are duplicated element found
           complexity++;
         }
          cnt--;
      }
 }
}
}

------解决方案--------------------
试了,好像没问题,这是测试代码,只比较了个数。都是52个。参照是sort, unique的结果。

#include <iostream>  
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;  
void removeDuip(int *arr,int &cnt);
int complexity=0;  


int sorted_remove_dup(int arr[], int cnt)
{
vector<int> v(arr, arr+cnt);
std::sort(v.begin(), v.end());
auto a=std::unique(v.begin(), v.end());
return a-v.begin();
}

int main()  
{  
    int arr[]={

23,4,8,6,-17,-11,-1,-16,21,-18,-16,-19,

-16,-3,-11,26,-4,-18,25,29,-3,-23,-14,-5,
6,-14,7,13,-16,-22,-12,-10,-4,1,-24,-14,
19,-28,26,14,0,5,-15,-2,28,3,2,-16,
0,8,11,-6,-7,30,-27,24,25,18,-24,-14,
-9,11,-21,14,-23,10,0,17,13,25,24,-9,
12,-18,-28,15,1,-1,25,7,8,22,19,5,
-19,-15,24,-28,0,-19,29,13,1,-1,-26,11,
-27,-25,2,-24
    };
    
//    string filename;
//    cout<<"enter file name:";
//    getline(cin,filename);
//    ifstream infile(filename.c_str());  
//    int count = 0;  
//    while(!infile.eof())  
//    {  
//        infile>>arr[count];  
//        ++count;  
//    }  
//    infile.close();
//     
//    //int size=sizeof(arr)/sizeof(int);
//   
 int cnt=sizeof(arr)/sizeof(arr[0]);
    for ( int j= 0; j < cnt; ++j)  
        cout<<arr[j]<<" ";  
    cout<<"the array size is "<<cnt<<endl;
     
    cout<<"The number of elements after removing dup with standard libary utility is "<<sorted_remove_dup(arr,cnt)<<endl;
 
  removeDuip(arr,cnt);
  
    for ( int j= 0; j < cnt; ++j)