视频讲解在这(谢谢各位大佬):👇
c语言代码实现数据结构课后代码题顺序表p18 2_哔哩哔哩_bilibili
本题代码如下
void nizhi(struct sqlist* s)
{int temp = 0;for (int i = 0; i < s->length / 2; i++){temp = s->a[i];s->a[i] = s->a[s->length - i - 1];s->a[s->length - 1 - i] = temp;}
}
完整测试代码
#include<stdio.h>
#define Max 50
struct sqlist
{int a[Max];int length;
};
void nizhi(struct sqlist* s)
{int temp = 0;for (int i = 0; i < s->length / 2; i++){temp = s->a[i];s->a[i] = s->a[s->length - i - 1];s->a[s->length - 1 - i] = temp;}
}
int main()
{struct sqlist s;int j = 0;s.length = 5;for (j = 0; j < s.length; j++)scanf("%d", &s.a[j]);printf("原先数组为:");for (j = 0; j < s.length; j++)printf("%d", s.a[j]);nizhi(&s);printf("\n逆置后的数组为:");for (j = 0; j < s.length; j++)printf("%d", s.a[j]);return 0;
}