调整队列

68 阅读1分钟
#include<bits/stdc++.h>
using namespace std;
struct node//链表结构体
{
	//标准配置
	int data;
	node *next;
};
int main()
{

	int n;
	node *head,*tail;//创建头尾指针
	head=new node;  //新建头元素
	head->data=0;   //赋值↓
	head->next=NULL; //啥也不指的指针
	tail=head;//目前最后一个
	cin>>n; //输入有几个元素

	for(int i=1; i<=n; i++)
	{
		 int x;
		 cin>>x;//每次输入一个数
		 node *p=new node;//捏出一个新指针
		 p->data=x;//赋值
		 p->next=NULL;//啥也不指
		 tail->next=p;//尾巴变了
		 tail=p;
		 
	}
	int id;
	cin>>id;//输入要出去的人的编号
	node *a=head; //从头开始
	node *key=head;//从头开始*2
	for(int i=1; i<=n; i++)
	{
		if(i!=id)
		{
			a=a->next;
			cout<<a->data<<" ";		
		}
		else
		{
			a=a->next;
		}
	}

	return 0;//没了
}