if
if
if
if (pnode==NULL){
(pnode==NULL){
(pnode==NULL){
(pnode==NULL){
cout<<
cout<<
cout<<
cout<< "Application
"Application
"Application
"Application error!"
error!"
error!"
error!" <<endl;
<<endl;
<<endl;
<<endl;
exit(1);
exit(1);
exit(1);
exit(1);
}
}
}
}
for
for
for
for (
(
(
( int
int
int
int i=0;i<n;i++){
i=0;i<n;i++){
i=0;i<n;i++){
i=0;i<n;i++){
pmove=pmove->m_pnext;
pmove=pmove->m_pnext;
pmove=pmove->m_pnext;
pmove=pmove->m_pnext;
if
if
if
if (pmove==head){
(pmove==head){
(pmove==head){
(pmove==head){
cout<<
cout<<
cout<<
cout<< "The
"The
"The
"The n
n
n
n is
is
is
is out
out
out
out of
of
of
of boundary"
boundary"
boundary"
boundary" <<endl;
<<endl;
<<endl;
<<endl;
return
return
return
return 0;
0;
0;
0;
}
}
}
}
}
}
}
}
pnode->m_pnext=pmove->m_pnext;
pnode->m_pnext=pmove->m_pnext;
pnode->m_pnext=pmove->m_pnext;
pnode->m_pnext=pmove->m_pnext;
pmove->m_pnext=pnode;
pmove->m_pnext=pnode;
pmove->m_pnext=pnode;
pmove->m_pnext=pnode;
return
return
return
return 1;
1;
1;
1;
}
}
}
}
template
template
template
template <
<
<
< typename
typename
typename
typename Type>
Type>
Type>
Type> bool
bool
bool
bool CircularList<Type>::RemoveAll(Type
CircularList<Type>::RemoveAll(Type
CircularList<Type>::RemoveAll(Type
CircularList<Type>::RemoveAll(Type item){
item){
item){
item){
ListNode<Type>
ListNode<Type>
ListNode<Type>
ListNode<Type> *pmove=head;
*pmove=head;
*pmove=head;
*pmove=head;
ListNode<Type>
ListNode<Type>
ListNode<Type>
ListNode<Type> *pdel=head->m_pnext;
*pdel=head->m_pnext;
*pdel=head->m_pnext;
*pdel=head->m_pnext;
while
while
while
while (pdel!=head){
(pdel!=head){
(pdel!=head){
(pdel!=head){
if
if
if
if (pdel->m_data==item){
(pdel->m_data==item){
(pdel->m_data==item){
(pdel->m_data==item){
pmove->m_pnext=pdel->m_pnext;
pmove->m_pnext=pdel->m_pnext;
pmove->m_pnext=pdel->m_pnext;
pmove->m_pnext=pdel->m_pnext;
delete
delete
delete
delete pdel;
pdel;
pdel;
pdel;
pdel=pmove->m_pnext;
pdel=pmove->m_pnext;
pdel=pmove->m_pnext;
pdel=pmove->m_pnext;
continue
continue
continue
continue ;
;
;
;
}
}
}
}
pmove=pmove->m_pnext;
pmove=pmove->m_pnext;
pmove=pmove->m_pnext;
pmove=pmove->m_pnext;
pdel=pdel->m_pnext;
pdel=pdel->m_pnext;
pdel=pdel->m_pnext;
pdel=pdel->m_pnext;
}
}
}
}
return
return
return
return 1;
1;
1;
1;
}
}
}
}
template
template
template
template <
<
<
< typename
typename
typename
typename Type>
Type>
Type>
Type> Type
Type
Type
Type CircularList<Type>::Remove(
CircularList<Type>::Remove(
CircularList<Type>::Remove(
CircularList<Type>::Remove( int
int
int
int n){
n){
n){
n){
if
if
if
if (n<0){
(n<0){
(n<0){
(n<0){
cout<<
cout<<
cout<<
cout<< "can't
"can't
"can't
"can't find
find
find
find the
the
the
the element"
element"
element"
element" <<endl;
<<endl;
<<endl;
<<endl;
exit(1);
exit(1);
exit(1);
exit(1);
}
}
}
}
ListNode<Type>
ListNode<Type>
ListNode<Type>
ListNode<Type> *pmove=head,*pdel;
*pmove=head,*pdel;
*pmove=head,*pdel;
*pmove=head,*pdel;
for
for
for
for (
(
(
( int
int
int
int i=0;i<n&&pmove->m_pnext!=head;i++){
i=0;i<n&&pmove->m_pnext!=head;i++){
i=0;i<n&&pmove->m_pnext!=head;i++){
i=0;i<n&&pmove->m_pnext!=head;i++){
pmove=pmove->m_pnext;
pmove=pmove->m_pnext;
pmove=pmove->m_pnext;
pmove=pmove->m_pnext;
}
}
}
}
if
if
if
if (pmove->m_pnext==head){
(pmove->m_pnext==head){
(pmove->m_pnext==head){
(pmove->m_pnext==head){
cout<<
cout<<
cout<<
cout<< "can't
"can't
"can't
"can't find
find
find
find the
the
the
the element"
element"
element"
element" <<endl;
<<endl;
<<endl;
<<endl;
exit(1);
exit(1);
exit(1);
exit(1);
}
}
}
}