4.3 List<int> L1(20);
L1.append(2);
L1.append(23);
L1.append(15);
L1.append(5);
L1.append(9);
L1.next( );
L1.next( );
4.5 template <class Elem>void LList<Elem>::reverse()
// Reverse LList
{ if(head->next == NULL) return;
// Now,reverse the list
Link<Elem>* p = head->next; // first
Link<Elem>* q = p->next; // second
p->next = NULL; // only one
while (q) // insert to first one by one
{ p=q->next; q->next=head->next; head->next=q; q = p; }
int t = leftcnt ; leftcnt = rightcnt; rightcnt = t;
setPos(leftcnt);
}
#include "LList.h"
void main()
{ LList<int> L1;
int i,j=0;
L1.append(j);
for(i=0; i<9; i++) { j=i*2+1; L1.insert(j); }
cout<<"List L1 is,";
L1.print ( );
cout<<"\nList L1 move next 2 pos,";
L1.next(); L1.next(); L1.print();
cout<<"\nList L1 remove,";
L1.remove(j); cout<<"Remove elem is " <<j <<endl;
cout<<"Set fence position = ";
cin>>i; L1.setPos(i);
cout<<"List L1 now is,"; L1.print();
LList<char> L2; char c;
cout<<"\nList L2 is,";
for(i=0; i<26; i++){ c=i+65; L2.append(c); }
L2.print();
for(i=0; i<10; i++)L2.next(); L2.print();
cout<<"\nList L2 reverse is,";
L2.reverse(); L2.print();
}
L1.append(2);
L1.append(23);
L1.append(15);
L1.append(5);
L1.append(9);
L1.next( );
L1.next( );
4.5 template <class Elem>void LList<Elem>::reverse()
// Reverse LList
{ if(head->next == NULL) return;
// Now,reverse the list
Link<Elem>* p = head->next; // first
Link<Elem>* q = p->next; // second
p->next = NULL; // only one
while (q) // insert to first one by one
{ p=q->next; q->next=head->next; head->next=q; q = p; }
int t = leftcnt ; leftcnt = rightcnt; rightcnt = t;
setPos(leftcnt);
}
#include "LList.h"
void main()
{ LList<int> L1;
int i,j=0;
L1.append(j);
for(i=0; i<9; i++) { j=i*2+1; L1.insert(j); }
cout<<"List L1 is,";
L1.print ( );
cout<<"\nList L1 move next 2 pos,";
L1.next(); L1.next(); L1.print();
cout<<"\nList L1 remove,";
L1.remove(j); cout<<"Remove elem is " <<j <<endl;
cout<<"Set fence position = ";
cin>>i; L1.setPos(i);
cout<<"List L1 now is,"; L1.print();
LList<char> L2; char c;
cout<<"\nList L2 is,";
for(i=0; i<26; i++){ c=i+65; L2.append(c); }
L2.print();
for(i=0; i<10; i++)L2.next(); L2.print();
cout<<"\nList L2 reverse is,";
L2.reverse(); L2.print();
}