试分别以顺序表和单链表作存储结构,各写一实现线性表就地逆置的算法


对数组的倒置
void SeqList::inversion()
{
    int i = 0, j = length - 1;
    DataType temp;
    while(i < j)
    {
        temp = data[i];
        data[i++] = data[j];
        data[j--] = temp;
    }
} 

对链表的倒置
void SeqList::inversion()
{
    Node * p, * q;
    p = first->next;
    q = p->next;
    while(q != NULL)
    {
        p = q;
        q = q->next;
        p->next = first->next;
        first->next = p;
    }

} 




你可能感兴趣的:(#,数据结构与算法)