순서표의 전환


  
  
  
  
  1. #include<iostream>  
  2. using namespace std;  
  3. typedef int ElemType;  
  4. const int MaxSize = 1000;  
  5. class SequenList  
  6. {  
  7.      protected:  
  8.          ElemType a[MaxSize];  
  9.          int len;  
  10.      public:  
  11.          void exchange( int n)  //  
  12.          {  
  13.              for(int i = 0;i<=n/2-1;i++)  
  14.              {  
  15.                  ElemType t = a[i];  
  16.                  a[i] = a[n-i-1];  
  17.                  a[n-i-1]=t;  
  18.              }  
  19.          }  
  20.          void input(int n)  
  21.          {  
  22.              len = n;  
  23.              for(int i = 0;i<n;i++)  
  24.              {  
  25.                  cin>>a[i];  
  26.              }  
  27.          }  
  28.          void print(int n)  
  29.          {  
  30.              for(int i = 0;i<=n-1;i++)  
  31.              {  
  32.                  cout<<a[i]<<' ';  
  33.              }  
  34.              cout<<endl;  
  35.          }  
  36.  
  37. };  
  38.  
  39.  
  40. int main()  
  41. {  
  42.     int n;  
  43.     cout<<" "<<endl;  
  44.     cin>>n;  
  45.     SequenList a;  
  46.     cout<<" "<<endl;  
  47.     a.input(n);  
  48.     a.print(n);  
  49.     a.exchange(n);  
  50.     a.print (n);  
  51.     system("pause");  
  52.     return 0;  

좋은 웹페이지 즐겨찾기