-
源代码
#include<iostream> #include<fstream> using namespace std; typedef int ElemType; const int n = 10; void MyExchange(ElemType *a, ElemType *b){ ElemType temp; temp = *a; *a = *b; *b = temp; } void InverseArry(ElemType arry[n], int n){ ElemType *p = & arry[0]; ElemType *q = & arry[ n - 1]; while (p < q)//指针不相遇 { MyExchange(p, q); p++; q--; } } void PrintArrya(ElemType arry[n], int n) { fstream f1; f1.open("t1.txt", ios::in | ios::app); cout << "逆序操作前:" << endl; for (int i = 0; i < n; i++) { f1 >> arry[i]; cout << arry[i] << endl; } } void PrintArryb(ElemType arry[n], int n){ cout << "逆序操作后:" << endl; for (int i = 0; i < n; ++i) { cout << arry[i] << endl; } cout << endl; } int main() { ElemType arr
C++ | 数组逆序 | 问题总结
最新推荐文章于 2023-02-09 00:07:43 发布