2.22

版权声明:本文为博主原创文章,转载需注明出处。 https://blog.csdn.net/zz_Caleb/article/details/83277521
#include<cstdio>
#include<malloc.h>
typedef struct table{
	int t;
	table *next,*last;
}node,*List;

void swap(int &a,int &b){
	int t=a;
	a=b;
	b=t;
}

int main()
{
	freopen("in.txt","r",stdin);
	int n;
	scanf("%d",&n);
	List head=(List)malloc(sizeof(node));
	List tail=head;
	for(int i=0;i<n;i++){
		List s=(List)malloc(sizeof(node));
		scanf("%d",&s->t);
		s->last=tail;
		tail->next=s;
		s->next=NULL;
		tail=s;
	}
	List h=head->next;
	for(int i=0;i<n/2;i++){
		swap(h->t,tail->t);
		h=h->next;
		tail=tail->last;
	}
	h=head->next;
	while(h){
		printf("%d\n",h->t);
		h=h->next;
	}
}

猜你喜欢

转载自blog.csdn.net/zz_Caleb/article/details/83277521
今日推荐