#include<stdio.h>
#include<stdlib.h>
#define max 1000000
typedef int ElemType;
typedef struct
{
ElemType *elem; //存储空间基地址
int length; //当前长度
int listSize; //当前分配的存储容量, 以sizeof(ElemType)为单位
}SqlList;
void creat(SqlList &L, int len)
{
L.elem = (ElemType*)malloc(max*sizeof(ElemType));
L.length = len;
L.listSize = max;
int i;
for(i=0; i<L.length; i++)
{
scanf("%d", &L.elem[i]);
}
}
void move(SqlList &L, int first, int last)
{
int i = 0, j, t;
for(j=first; j<=(first+last)/2; j++)
{
i++;
t = L.elem[j-1];
L.elem[j-1] = L.elem[last-i];
L.elem[last-i] = t;
}
}
void print(SqlList &L, int n)
{
int j;
for(j=0; j<n-1; j++)
{
printf("%d ", L.elem[j]);
}
printf("%d\n", L.elem[j]);
}
int main()
{
int n, m, size;
SqlList L;
scanf("%d", &size);
while(size--)
{
scanf("%d%d", &n, &m);
creat(L, n);
move(L, 1, n);
// print(L, n);
move(L, 1, n-m);
// print(L, n);
move(L, n-m+1, n);
print(L, n);
}
return 0;
}
顺序表-部分元素逆置
最新推荐文章于 2024-11-16 12:15:37 发布