链表c++ link-list 在做对字符串做reverse时,为啥我的程序只能输出前两个字符呢?


#include"LinkedList.h"
#include<iostream>
using namespace std;
int main()
{

LList<int> L1;
cout<<"The current position is:"<<L1.currPos()<<endl;
cout<<"The length of L1 is:"<<L1.length()<<endl;
L1.append(2);
L1.append(23);
L1.append(15);
L1.append(5);
L1.append(9);
cout<<"Now the List is:"<<endl;
L1.printList();
L1.reverse();
cout<<"After reversing,now the list is:"<<endl;
L1.printList();
    
}

```c++
void reverse()
    {
        Link<E> *temp1;
        Link<E> *temp2;
        Link<E> *temp3;
        Link<E> *temp4;
        temp4=head->next;
        temp1=head->next;
        temp2=temp1->next;
        head->next=NULL;
        tail->next=NULL;
        //cout<<"tail->next:"<<tail->next<<endl;
        while(temp2)
        {
            temp1->next=NULL;
            temp3=temp2->next;
            temp2->next=temp1;
            temp1=temp2;
            temp2=temp3;
            //cout<<"zhixingyici"<<endl;
            //cout<<"temp1="<<temp1->element<<endl;
                //if(temp2) cout<<"temp2="<<temp2->element<<endl;
        }
        //cout<<"chuxunhuan"<<endl;
        head->next=temp1;
        //cout<<"head->next"<<head->next->element<<endl;
        tail=temp4;
        //cout<<"tail"<<tail->element<<endl;

        cout<<"In the reverse:"<<endl;
        Link<E> *temp;
        temp=head->next;
        cout<<"<";
        for(;temp<=curr;temp=temp->next)
        {
            cout<<temp->element<<",";
        }
        cout<<"|";
        for(temp=curr->next;temp!=tail;)
        {
            cout<<temp->element<<",";
            temp=temp->next;
            //cout<<"temp->next:"<<temp->element<<endl;
        }
        cout<<tail->element<<">"<<endl;



    }

```