SWUST OJ(1101)
顺序表中的数据的循环移动
1 #include <iostream> 2 #include <cstdlib> 3 using namespace std; 4 5 int main() 6 { 7 int *data, n, x; 8 cin>>n; 9 10 data = (int*)malloc(n*sizeof(int)); 11 12 for (int i = 0; i < n; ++i) 13 { 14 cin>>data[i]; 15 } 16 17 cin>>x; 18 if (x<0 || x > n) 19 { 20 cout<<"error!"; 21 return 0; 22 } 23 24 for (int i = x; i <n; ++i) 25 { 26 cout<<data[i]<<" "; 27 } 28 29 for (int i = 0; i < x; ++i) 30 { 31 cout<<data[i]<<" "; 32 } 33 34 return 0; 35 }
注:顺序表本身并没有改变只是在输出顺序上做了点改变