C++程序设计实践指导1.1删除序列中相同的数改写要求实现

改写要求1:改写为以指针为数据结构

#include <iostream>
#include <cstdlib> using namespace std; class ARP
{
int m;
int* p;
int count[10]; public:
ARP(int x[],int size)
{
m = size;
p = new int [m];
for (int i =0;i<m;i++)
{
p[i]=x[i];
}
for (int i =0;i<m;i++)
{
count[i]=1;
}
}
void delsame();
void show1();
void show2();
~ARP()
{
delete [] p;
}
};
void ARP::show1()
{
for(int i=0;i<m;i++)
{
cout<<p[i]<<"\t"; }
cout<<endl;
}
void ARP::show2()
{
for(int i=0;i<m;i++)
{
cout<<p[i]<<"\t"; }
for(int i=0;i<m;i++)
{
cout<<count[i]<<"\t"; }
cout<<endl;
}
void ARP::delsame()
{
int i,j;
for(i=0;i<m-1;i++)
{
if(p[i]==p[i+1])
{
count[i]=count[i]+1;
for(j=i+1;j<m-1;j++)
{
p[j]=p[j+1];
}
m --;
i --;
}
}
}
int main()
{ int b[16] = {1,2,2,3,4,4,5,6,6,7,8,8,8,9,10,10};
ARP temp(b,sizeof(b)/sizeof(b[0]));
temp.show1();
temp.delsame();
temp.show2();
system("pause") ;
return 0;
}

  

上一篇:WEB前端开发工程师成长计划


下一篇:.net 关于数据库的链接