Rewrite requirement 1: Overwrite as pointer to data structure
#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::d elsame () {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; }
C + + Programming Practice Guide 1.1 delete sequence in the same number rewrite requirement implementation