1个回答
展开全部
#include<stdio.h>
void main()
{
void reverse(int *ptr, int left, int right);
void swap(int *ptr, int a, int b);
int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int k = 0;
int left = 0, right = 9;
printf("请输入需要逆置的个数:\n");
scanf("%d", &k);
right = k - 1;
reverse(a, left, right);
for(int i = 0; i < 10; i++)
printf("%d ", a[i]);
printf("\n");
}
void swap(int *ptr, int a, int b)
{
int temp;
temp = *(ptr + a);
*(ptr + a) = *(ptr + b);
*(ptr + b) = temp;
}
void reverse(int *ptr, int left, int right)
{
if((left == right) || (left > right))
return;
swap(ptr, left, right);
left++;
right--;
reverse(ptr, left, right);
}
void main()
{
void reverse(int *ptr, int left, int right);
void swap(int *ptr, int a, int b);
int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int k = 0;
int left = 0, right = 9;
printf("请输入需要逆置的个数:\n");
scanf("%d", &k);
right = k - 1;
reverse(a, left, right);
for(int i = 0; i < 10; i++)
printf("%d ", a[i]);
printf("\n");
}
void swap(int *ptr, int a, int b)
{
int temp;
temp = *(ptr + a);
*(ptr + a) = *(ptr + b);
*(ptr + b) = temp;
}
void reverse(int *ptr, int left, int right)
{
if((left == right) || (left > right))
return;
swap(ptr, left, right);
left++;
right--;
reverse(ptr, left, right);
}
追问
能给个运行结果吗?我们交作业,还要运行结果。谢谢了。。谢谢。。
追答
输入:5
输出:5 4 3 2 1 6 7 8 9 10
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询