C + + Programming Practice Guide 1.1 delete sequence in the same number rewrite requirement implementation

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.