实现顺序表逆置,在原数组上操作

//C++ file

#include <stdlib.h>
using namespace std;

int main(int argc, char const *argv[])
{
    int x[5] = {1, 2, 3, 4, 5};
    int len = sizeof(x);
    for (int i = 0; i < len; i++)
    {
        cout << x[i] << endl;
    }
   for (int i = 0; i <= len / 2; i++)
    {
        int tmp = x[i];
        x[i] = x[len - i];
        x[len - i] = tmp;
    }
    for (int i = 0; i < len; i++)
    {
        cout << x[i] << endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_40627841/article/details/82150508