线性表
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
vector <int> merge(vector <int> a,vector <int> b)
{
//合并
int i = 0, j = 0;
vector <int> res;
while(i < a.size() && j < b.size())
{
if (a[i] < b[j]) res.push_back(a[i++]);
else res.push_back(b[j++]);
}
while(i < a.size()) res.push_back(a[i++]);
while(j < b.size()) res.push_back(b[j++]);
return res;
}
void del_same(int arr[], int n)
{//删除重复元素
if(!n) return;
int j = 0;
for(int i = 0; i < n; i++)
{
if(arr[i] == arr[i+1]) continue;
arr[j] = arr[i];
j++;
}
n = j;
for(int i = 0; i < n; i++) cout<<arr[i]<<' ';
cout<<endl;
}
void fun(vector <int> &arr,int x)
{
//find_success swap(i,i+1) fail insert
int low = 0, high = arr.size()-1;
//二分查找
while(low <= high)
{
int mid = (low + high) >> 1;
if(arr[mid] == x)
{
if((mid+1) < arr.size())
swap(arr[mid], arr[mid+1]);
return;
}
else if (x >= arr[mid]) low = mid + 1;
else high = mid - 1;
}
//找不到插入
arr.resize(arr.size() + 1);
for(int i = arr.size()-1; i > low; i--)
arr[i] = arr[i-1];
arr[low] = x;
}
int main()
{
// int a[] = {1,2,2,3,6,7,8};
// int n = sizeof(a) / sizeof(int);
vector <int> a1 = {1,4,5,6,9};
//vector <int> b1 = {2,3,6};
fun(a1,2);
for(auto x : a1) cout<<x<<' ';
cout<<endl;
//vector <int> res = merge(a1,b1);
//for(int i = 0; i < res.size(); i++) cout<<res[i]<<' ';
//del_same(a,n);
return 0;
}
int main()
{
int n,p;
cin>>n>>p;
queue <int> q;
while(n--)
{
int x;
cin>>x;
q.push(x);
}
for(int i = 0; i < p; i++)
{
int t = q.front();
q.pop();
q.push(t);
}
while (q.size())
{
cout<<q.front()<<' ';
q.pop();
}
cout<<endl;
return 0;
}