注意:先將順序表元素調整爲符合要求的內容後,再做輸出,輸出過程只能用一個循環語句實現,不能分成兩個部分。
Input
之後輸入n行,每行先輸入整數len與整數m(分別代表本表的元素總數與前半表的元素個數),之後輸入len個整數,代表對應順序表的每個元素。
Output
Example Input
2
10 3 1 2 3 4 5 6 7 8 9 10
5 3 10 30 20 50 80
Example Output
4 5 6 7 8 9 10 1 2 3
50 80 10 30 20
Hint
注意:先將順序表元素調整爲符合要求的內容後,再做輸出,輸出過程只能在一次循環中完成,不能分成兩個部分輸出。
#include<iostream>
#include<stdlib.h>
using namespace std;
const int maxsize = 100000;
class List
{
int data[maxsize];
public:
int size;
List(); //初始化
bool isEmpty();
bool isFull();
void Creat(int e);
void Change(int m); //元素位移
void Print();
};
List::List()
{
size = 0;
}
bool List:: isFull()
{
if (size == maxsize - 1) return true;
else return false;
}
bool List::isEmpty()
{
if (size == 0) return true;
else return false;
}
void List::Creat(int e)
{
if (isFull()) exit(0);
else
{
data[size] = e;
size++;
}
}
void List::Change(int m)
{
int t;
while (m--)
{
t = data[0];
for (int i = 0; i < size - 1; i++)
data[i] = data[i + 1];
data[size - 1] = t;
}
}
void List::Print()
{
int i;
for ( i = 0; i < size - 1; i++)
cout << data[i] << " ";
cout << data[size-1] << endl;
}
int main()
{
int n; cin >> n; while (n--)
{
List L;
int num, m,t;
cin >> num >> m;
for (int i = 0; i < num; i++)
{
cin >> t;
L.Creat(t);
}
L.Change(m);
L.Print();
}
return 0;
}