顺序表所有元素逆置,空间复杂度O(1)

    技术2024-11-06  10

    #include <iostream> using namespace std; //#define Maxsize 10 typedef struct { int length=10; int data[10]={0,1,2,3,4,5,6,7,8,9}; }SqList; void Reverse(SqList &L) { int temp; for(int i=0;i<=L.length/2-1;i++) { temp=L.data[i]; L.data[i]=L.data[L.length-i-1]; L.data[L.length-i-1]=temp; } } int main() { SqList L; Reverse(L); for(int i=0;i<L.length;i++) cout<<L.data[i]<<" "; cout<<endl; return 0; }

     

    Processed: 0.030, SQL: 9