chain.cpp
#include <iostream>
#include <sstream>
#include <iterator>
using namespace std;
template <class T>
class linearList
{
public:
virtual ~linearList(){}
virtual bool empty() const = 0;
virtual int size() const = 0;
virtual T& get(int theIndex) const = 0;
virtual int indexOf(const T& theElement) const = 0;
virtual void erase(int theIndex) = 0;
virtual void insert(int theIndex, const T& theElement) = 0;
virtual void output(ostream& out) const = 0;
};
template <class T>
struct chainNode
{
public:
chainNode(){}
chainNode(const T& element)
{
this->element = element;
}
chainNode(const T& element,chainNode<T>* next)
{
this->element = element;
this->next = next;
}
T element;
chainNode<T> *next;
};
template<class T>
class chain : public linearList<T>
{
public:
chain(int initialCapacity = 10);
chain(const chain<T>&);
~chain();
bool empty() const override { return listSize == 0;}
int size() const override {return listSize;}
T& get(int theIndex) const override;
int indexOf(const T& theElement) const override;
void erase(int theIndex) override;
void insert(int theIndex, const T& theElement) override;
void output(ostream& out) const override;
T getFirstNode(){return firstNode->element;}
T getLastNode(){return lastNode->element;}
void clear();
void push_back(const T& theElement);
void setSize(int theSize);
void set(int theIndex,const T& theElement);
void removeRange(int fromIndex,int toIndex);
int lastIndexOf(const T& theElement) const;
chainNode<T>& operator[](int theIndex);
bool operator==(const chain<T>& right) const;
bool operator!=(const chain<T>& right) const;
bool operator<(const chain<T>& right) const;
void swap(chain<T>& right);
void leftShift(int i);
void reverse();
chain<T>& meld1(const chain<T>& a, const chain<T>& b);
chain<T>& meld2(chain<T>& a, chain<T>& b);
chain<T>& merge1(chain<T>& a, chain<T>& b);
chain<T>& merge2(chain<T>& a, chain<T>& b);
chain<T>& split(chain<T>& a, chain<T>& b);
public:
class iterator
{
public:
typedef forward_iterator_tag iterator_capacity;
typedef T value_type;
typedef ptrdiff_t difference_type;
typedef T* pointer;
typedef T& reference;
iterator(chainNode<T>* theNode = NULL)
{
node = theNode;
}
T& operator*() const { return node->element; }
T* operator->() const { return &node->element; }
iterator& operator++()
{
node = node->next;
return *this;
}
iterator operator++(int)
{
iterator old = *this;
node = node->next;
return old;
}
bool operator!=(const iterator right) const
{
return node != right.node;
}
bool operator==(const iterator right) const
{
return node == right.node;
}
protected:
chainNode<T>* node;
};
iterator begin(){ return iterator(firstNode);}
iterator end(){return iterator(NULL);}
protected:
void checkIndex(int theIndex) const;
chainNode<T>* firstNode;
chainNode<T>* lastNode;
int listSize;
};
template<class T>
chain<T>::chain(int initialCapacity)
{
if(initialCapacity < 1)
{
ostringstream s;
s<<"Initial capacity = "<<initialCapacity<<" must be >0";
throw logic_error(s.str());
}
firstNode = NULL;
listSize = 0;
lastNode = 0;
}
template<class T>
chain<T>::chain(const chain<T>& theList)
{
listSize = theList.listSize;
if(listSize == 0)
{
firstNode = NULL;
return;
}
chainNode<T>* sourceNode = theList.firstNode;
firstNode = new chainNode<T>(sourceNode->element);
sourceNode = sourceNode->next;
chainNode<T>* targetNode = firstNode;
while(sourceNode != NULL)
{
targetNode->next = new chainNode<T>(sourceNode->element);
targetNode = targetNode->next;
sourceNode = sourceNode->next;
}
targetNode->next = NULL;
}
template<class T>
chain<T>::~chain()
{
while(firstNode != NULL)
{
chainNode<T>* nextNode = firstNode->next;
delete firstNode;
firstNode = nextNode;
}
lastNode = NULL;
}
template<class T>
T& chain<T>::get(int theIndex) const
{
checkIndex(theIndex);
chainNode<T>* currentNode = firstNode;
for(int i = 0; i < theIndex && currentNode; i++)
{
currentNode = currentNode->next;
}
return currentNode->element;
}
template<class T>
int chain<T>::indexOf(const T& theElement) const
{
chainNode<T>* currentNode = firstNode;
int index = 0;
while(currentNode != NULL &&
currentNode->element != theElement)
{
currentNode = currentNode->next;
index++;
}
if(currentNode == NULL)
return -1;
else
return index;
}
template<class T>
void chain<T>::erase(int theIndex)
{
checkIndex(theIndex);
chainNode<T>* deleteNode;
if(theIndex == 0)
{
deleteNode = firstNode;
firstNode = firstNode->next;
}
else
{
chainNode<T>*p = firstNode;
for(int i = 0; i < theIndex - 1;i++)
p = p->next;
deleteNode = p->next;
p->next = p->next->next;
if(p->next->next == NULL)
{
lastNode = p->next;
}
}
listSize--;
delete deleteNode;
}
template<class T>
void chain<T>::insert(int theIndex,const T& theElement)
{
if(theIndex < 0 || theIndex > listSize)
{
ostringstream s;
s<<"index = "<<theIndex <<" size = "<<listSize;
throw logic_error(s.str());
}
if(theIndex == 0)
{
firstNode = new chainNode<T>(theElement,firstNode);
if(listSize == theIndex)
{
lastNode = firstNode;
}
}
else
{
chainNode<T>* p = firstNode;
for(int i = 0;i < theIndex - 1;i++)
p = p->next;
p->next = new chainNode<T>(theElement,p->next);
if(theIndex == listSize-1)
{
lastNode = p->next->next;
}
}
listSize++;
}
template<class T>
void chain<T>::output(ostream& out) const
{
for(chainNode<T>* currentNode = firstNode;
currentNode != NULL;
currentNode = currentNode->next)
{
out<<currentNode->element<<" ";
}
}
template<class T>
ostream& operator<<(ostream& out, const chain<T>& x)
{
x.output(out);
return out;
}
template<class T>
void chain<T>::clear()
{
while(firstNode != NULL)
{
chainNode<T>* nextNode = firstNode->next;
delete firstNode;
firstNode = nextNode;
}
listSize = 0;
};
template<class T>
void chain<T>::push_back(const T& theElement)
{
chainNode<T>* newNode = new chainNode<T>(theElement,NULL);
if(firstNode == NULL)
{
firstNode = lastNode = newNode;
}
else
{
lastNode->next = newNode;
lastNode = newNode;
}
listSize++;
}
template<class T>
void chain<T>::checkIndex(int theIndex) const
{
if(theIndex < 0 || theIndex >= listSize)
{
ostringstream s;
s << "index = " << theIndex << " size = " << listSize;
throw logic_error(s.str());
}
}
template<class T>
void chain<T>::setSize(int theSize)
{
if(listSize == 0 || theSize >= listSize)
{
cout<<"listSize == 0 || theSize >= listSize";
return;
}
chainNode<T>* currentNode = firstNode;
for(int i = 0; i < theSize-1; i++)
{
currentNode = currentNode->next;
}
chainNode<T>* prev = currentNode;
if(theSize == 0)
{
firstNode = nullptr;
}
else
{
currentNode = currentNode->next;
lastNode = prev;
prev->next = nullptr;
}
for(int i = theSize; i < listSize-1;i++)
{
prev = currentNode;
currentNode = currentNode->next;
delete prev;
}
listSize = theSize;
}
template<class T>
void chain<T>::set(int theIndex,const T& theElement)
{
checkIndex(theIndex);
if(theIndex == 0)
{
firstNode->element = theElement;
return;
}
chainNode<T>* currentNode = firstNode;
for(int i = 0; i < theIndex; i++)
{
currentNode = currentNode->next;
}
currentNode->element = theElement;
}
template<class T>
void chain<T>::removeRange(int fromIndex,int toIndex)
{
checkIndex(fromIndex);
checkIndex(toIndex);
if(toIndex < fromIndex)
{
return;
}
chainNode<T>* currentNode = firstNode;
for(int i = 1;i < fromIndex;i++)
{
currentNode = currentNode->next;
}
chainNode<T>* preDeleteNode = currentNode;
if(toIndex == listSize - 1)
{
lastNode = currentNode;
}
for(int i = fromIndex;i < toIndex; i++)
{
if(fromIndex == 0)
{
firstNode = currentNode->next;
delete currentNode;
currentNode = firstNode;
}
else
{
currentNode = preDeleteNode->next;
preDeleteNode->next= currentNode->next;
delete currentNode;
}
}
listSize = listSize - (toIndex - fromIndex);
}
template<class T>
int chain<T>::lastIndexOf(const T& theElement) const
{
if(listSize < 1) return -1;
int index = -1;
chainNode<T>* currentNode = firstNode;
for(int i = 0;i < listSize; i++)
{
if(currentNode->element == theElement)
{
index = i;
}
currentNode = currentNode->next;
}
return index;
}
template<class T>
chainNode<T>& chain<T>::operator[](int theIndex)
{
checkIndex(theIndex);
chainNode<T>* currentNode = firstNode;
if(theIndex == 0)
{
return *currentNode;
}
for(int i = 0;i < theIndex;i++)
{
currentNode = currentNode->next;
}
return *currentNode;
}
template<class T>
bool chain<T>::operator==(const chain<T>& right) const
{
if(listSize == 0 && right.listSize == 0)
return true;
if(listSize != right.listSize)
return false;
chainNode<T>* currentNode1 = firstNode;
chainNode<T>* currentNode2 = right.firstNode;
for(int i = 0;i < listSize;i++)
{
if(currentNode1->element != currentNode2->element)
return false;
currentNode1 = currentNode1->next;
currentNode2 = currentNode2->next;
}
return true;
}
template<class T>
bool chain<T>::operator!=(const chain<T>& right) const
{
return !(*this == right);
}
template<class T>
bool chain<T>::operator<(const chain<T>& right) const
{
if(listSize == 0 && right.listSize > 0) return true;
if(listSize > 0 && right.listSize == 0) return false;
int small = listSize <= right.listSize ? listSize : right.listSize;
chainNode<T>* cur1 = firstNode;
chainNode<T>* cur2 = right.firstNode;
for (int i = 0; i < small; i++){
if(cur1->element < cur2->element) return true;
if (cur1->element > cur2->element) return false;
cur1 = cur1->next;
cur2 = cur2->next;
}
if(cur2 != nullptr) return true;
return false;
}
template<class T>
void chain<T>::swap(chain<T>& right)
{
std::swap(firstNode,right.firstNode);
std::swap(lastNode,right.lastNode);
std::swap(listSize,right.listSize);
}
template<class T>
void chain<T>::leftShift(int i)
{
if(i < 0 || i>listSize)
{
ostringstream s;
s<<"i < 0 || i>listSize";
throw logic_error(s.str());
}
if(int i = 0)
{
return;
}
chainNode<T>* currentNode = firstNode;
for(int j = 0;j < i; j++)
{
firstNode = currentNode->next;
delete currentNode;
currentNode = firstNode;
listSize--;
}
}
template<class T>
void chain<T>::reverse()
{
if(listSize <= 0) return ;
chainNode<T>* currentNode = firstNode->next;
chainNode<T>* nextNode = currentNode->next;
firstNode->next = nullptr;
lastNode = firstNode;
while(nextNode)
{
currentNode->next = firstNode;
firstNode = currentNode;
currentNode = nextNode;
nextNode = nextNode->next;
}
currentNode->next = firstNode;
firstNode = currentNode;
}
template<class T>
chain<T>& chain<T>::meld1(const chain<T>& a, const chain<T>& b)
{
if(a.listSize == 0 && b.listSize == 0)
{
return *this;
}
chainNode<T>* currentNodeA = a.firstNode;
chainNode<T>* currentNodeB = b.firstNode;
firstNode = new chainNode<T>(currentNodeA->element);
chainNode<T>* currentNode = firstNode;
currentNodeA = currentNodeA->next;
while(currentNodeA && currentNodeB)
{
currentNode->next = new chainNode<T>(currentNodeA->element);
currentNode = currentNode->next;
currentNodeA = currentNodeA->next;
currentNode->next = new chainNode<T>(currentNodeB->element);
currentNode = currentNode->next;
currentNodeB = currentNodeB->next;
}
while(currentNodeA)
{
currentNode->next = new chainNode<T>(currentNodeA->element);
currentNode = currentNode->next;
if(!currentNodeA->next)
{
currentNode->next = nullptr;
lastNode = currentNode;
}
currentNodeA = currentNodeA->next;
}
while(currentNodeB)
{
currentNode->next = new chainNode<T>(currentNodeB->element);
currentNode = currentNode->next;
if(!currentNodeB->next)
{
currentNode->next = nullptr;
lastNode = currentNode;
}
currentNodeB = currentNodeB->next;
}
listSize = a.listSize+b.listSize;
return *this;
}
template<class T>
chain<T>& chain<T>::meld2(chain<T>& a, chain<T>& b)
{
if(a.listSize == 0 && b.listSize == 0)
{
return *this;
}
chainNode<T>* currentNodeA = a.firstNode;
chainNode<T>* currentNodeB = b.firstNode;
firstNode = currentNodeA;
chainNode<T>* currentNode = firstNode;
currentNodeA = currentNodeA->next;
while(currentNodeA && currentNodeB)
{
currentNode->next = currentNodeA;
currentNode = currentNode->next;
currentNodeA = currentNodeA->next;
currentNode->next = currentNodeB;
currentNode = currentNode->next;
currentNodeB = currentNodeB->next;
}
while(currentNodeA)
{
currentNode->next = currentNodeA;
currentNode = currentNode->next;
if(!currentNodeA->next)
{
currentNode->next = nullptr;
lastNode = currentNode;
}
currentNodeA = currentNodeA->next;
}
while(currentNodeB)
{
currentNode->next = currentNodeB;
currentNode = currentNode->next;
if(!currentNodeB->next)
{
currentNode->next = nullptr;
lastNode = currentNode;
}
currentNodeB = currentNodeB->next;
}
listSize = a.listSize+b.listSize;
a.firstNode = b.firstNode = nullptr;
a.lastNode = b.lastNode = nullptr;
a.listSize = b.listSize = 0;
return *this;
}
template<class T>
chain<T>& chain<T>::merge1(chain<T>& a, chain<T>& b)
{
chainNode<T>* currentNodeA = a.firstNode;
chainNode<T>* currentNodeB = b.firstNode;
chainNode<T>* currentNodeC = firstNode;
while(currentNodeA || currentNodeB)
{
if(currentNodeA == nullptr ||
currentNodeB != nullptr &&
currentNodeA->element > currentNodeB->element)
{
if(!firstNode)
{
firstNode = new chainNode<T>(currentNodeB->element);
currentNodeC = firstNode;
}
else
{
currentNodeC->next = currentNodeB;
currentNodeC = new chainNode<T>(currentNodeB->element);;
}
currentNodeB = currentNodeB->next;
}
else if(currentNodeB == nullptr ||
currentNodeA != nullptr &&
currentNodeA->element <= currentNodeB->element)
{
if(!firstNode)
{
firstNode = new chainNode<T>(currentNodeA->element);;
currentNodeC = firstNode;
}
else
{
currentNodeC->next = currentNodeA;
currentNodeC = new chainNode<T>(currentNodeA->element);;
}
currentNodeA = currentNodeA->next;
}
lastNode = currentNodeC;
listSize = a.listSize + b.listSize;
a.firstNode = b.firstNode = nullptr;
a.lastNode = b.lastNode = nullptr;
a.listSize = b.listSize = 0;
return *this;
}
}
template<class T>
chain<T>& chain<T>::merge2(chain<T>& a, chain<T>& b)
{
chainNode<T>* currentNodeA = a.firstNode;
chainNode<T>* currentNodeB = b.firstNode;
chainNode<T>* currentNodeC = firstNode;
while(currentNodeA || currentNodeB)
{
if(currentNodeA == nullptr ||
currentNodeB != nullptr &&
currentNodeA->element > currentNodeB->element)
{
if(!firstNode)
{
firstNode = currentNodeB;
currentNodeC = firstNode;
}
else
{
currentNodeC->next = currentNodeB;
currentNodeC = currentNodeB;
}
currentNodeB = currentNodeB->next;
}
else if(currentNodeB == nullptr ||
currentNodeA != nullptr &&
currentNodeA->element <= currentNodeB->element)
{
if(!firstNode)
{
firstNode = currentNodeA;
currentNodeC = firstNode;
}
else
{
currentNodeC->next = currentNodeA;
currentNodeC = currentNodeA;
}
currentNodeA = currentNodeA->next;
}
lastNode = currentNodeC;
listSize = a.listSize + b.listSize;
a.firstNode = b.firstNode = nullptr;
a.lastNode = b.lastNode = nullptr;
a.listSize = b.listSize = 0;
return *this;
}
}
template<class T>
chain<T>& chain<T>::split(chain<T>& a, chain<T>& b)
{
chainNode<T>* currentNode = firstNode;
chainNode<T>* next = nullptr;
chainNode<T>* currentNodeA = nullptr;
chainNode<T>* currentNodeB = nullptr;
for(int i = 0; i<listSize && currentNode;++i)
{
next = currentNode->next;
if(i % 2 == 0)
{
if(i == 0)
{
a.firstNode = currentNode;
currentNodeA = currentNode;
}
else
{
currentNodeA->next = currentNode;
currentNodeA = currentNode;
currentNodeA->next = nullptr;
}
a.listSize++;
}
else
{
if(i == 1)
{
b.firstNode = currentNode;
currentNodeB = currentNode;
}
else
{
currentNodeB->next = currentNode;
currentNodeB = currentNode;
currentNodeB->next = nullptr;
}
b.listSize++;
}
currentNode = next;
}
firstNode = nullptr;
listSize = 0;
return *this;
}
int main()
{
cout<<"----------------------size start--------------------"<<endl;
chain<double> list1;
cout<<list1.size()<<endl;
cout<<"----------------------size end--------------------"<<endl;
cout<<"----------------------insert start--------------------"<<endl;
for(int i = 0;i < 10;i++)
{
list1.insert(0,i);
}
cout<<list1.size()<<endl;
cout<<list1<<endl;
cout<<"----------------------insert end--------------------"<<endl;
cout<<"----------------------get start--------------------"<<endl;
for(int i = 0;i < 10;i++)
{
cout<<list1.get(i)<<" ";
}
cout<<endl;
cout<<"----------------------get end--------------------"<<endl;
cout<<"----------------------erase start--------------------"<<endl;
cout<<list1<<endl;
cout<<list1.size()<<endl;
for(int i = 0;i < 6;i++)
{
list1.erase(0);
}
cout<<list1<<endl;
cout<<list1.size()<<endl;
cout<<"----------------------erase end--------------------"<<endl;
cout<<"----------------------push_back start--------------------"<<endl;
cout<<list1<<endl;
for(int i = 0;i < 10;i++)
{
list1.insert(3,i);
}
cout<<list1<<endl;
cout<<list1.size()<<endl;
for(int i = 0;i < 3;i++)
{
list1.push_back(1000);
}
cout<<list1<<endl;
cout<<list1.size()<<endl;
cout<<"----------------------push_back end--------------------"<<endl;
cout<<"----------------------iterator start--------------------"<<endl;
chain<double>::iterator iter;
for(iter = list1.begin();iter != list1.end();iter++)
{
cout<<*iter<<" ";
}
cout<<endl;
cout<<"----------------------iterator end--------------------"<<endl;
cout<<"----------------------setSize start--------------------"<<endl;
cout<<list1<<endl;
cout<<list1.size()<<endl;
list1.setSize(2);
cout<<list1<<endl;
cout<<list1.size()<<endl;
cout<<"----------------------setSize end--------------------"<<endl;
cout<<"----------------------set start--------------------"<<endl;
for(int i = 0;i < 5;i++)
{
list1.push_back(i);
}
cout<<list1<<endl;
cout<<list1.size()<<endl;
list1.set(2,10000);
cout<<list1.get(2)<<endl;
cout<<list1<<endl;
cout<<list1.size()<<endl;
cout<<"----------------------set end--------------------"<<endl;
cout<<"----------------------removeRange start--------------------"<<endl;
cout<<list1.size()<<endl;
cout<<list1<<endl;
list1.removeRange(2,5);
cout<<list1<<endl;
cout<<list1.size()<<endl;
cout<<"lastNode = "<<list1.getLastNode()<<endl;
cout<<"----------------------removeRange end--------------------"<<endl;
cout<<"----------------------lastIndexOf start--------------------"<<endl;
cout<<list1.size()<<endl;
cout<<list1<<endl;
cout<<list1.lastIndexOf(3)<<endl;
cout<<list1.size()<<endl;
cout<<list1<<endl;
cout<<"----------------------lastIndexOf end--------------------"<<endl;
cout<<"----------------------operator[] start--------------------"<<endl;
cout<<list1<<endl;
cout<<list1.size()<<endl;
for(int i = 0;i < list1.size();i++)
{
cout<<list1[i].element<<" ";
}
cout<<endl;
cout<<list1.size()<<endl;
cout<<list1[0].element<<" ";
cout<<list1[1].element<<" ";
cout<<list1[2].element<<" ";
cout<<list1[3].element<<" ";
cout<<endl;
for(int i = 0;i < list1.size();i++)
{
list1[i].element = i;
}
cout<<list1<<endl;
cout<<"----------------------operator[] end--------------------"<<endl;
cout<<"----------------------operator== start--------------------"<<endl;
chain<double> list2;
for(int i = 0;i < 4;i++)
{
list2.push_back(i);
}
cout<<list2<<endl;
cout<<(list2==list1)<<endl;
cout<<"----------------------operator== end--------------------"<<endl;
cout<<"----------------------operator!= start--------------------"<<endl;
cout<<(list2!=list1)<<endl;
cout<<"----------------------operator!= end--------------------"<<endl;
cout<<"----------------------leftShift start--------------------"<<endl;
cout<<list1<<endl;
list1.leftShift(2);
cout<<list1<<endl;
cout<<"----------------------leftShift end--------------------"<<endl;
cout<<"----------------------reverse start--------------------"<<endl;
cout<<list2<<endl;
cout<<list2.getLastNode()<<endl;
list2.reverse();
cout<<list2<<endl;
cout<<list2.getLastNode()<<endl;
cout<<"----------------------reverse end--------------------"<<endl;
cout<<"----------------------meld1 start--------------------"<<endl;
cout<<list1<<endl;
cout<<list2<<endl;
chain<double> list3;
list3.meld1(list1,list2);
cout<<list3<<endl;
cout<<list3.getLastNode()<<endl;
cout<<list3.size()<<endl;
cout<<"----------------------meld1 end--------------------"<<endl;
cout<<"----------------------meld2 start--------------------"<<endl;
cout<<list1<<endl;
cout<<list2<<endl;
chain<double> list4;
list4.meld2(list1,list2);
cout<<list1<<endl;
cout<<list2<<endl;
cout<<list4<<endl;
cout<<list4.getLastNode()<<endl;
cout<<list4.size()<<endl;
cout<<"----------------------meld2 end--------------------"<<endl;
cout<<"----------------------split start--------------------"<<endl;
cout<<list1<<endl;
cout<<list2<<endl;
cout<<list4<<endl;
list4.split(list1,list2);
cout<<list1<<endl;
cout<<list2<<endl;
cout<<list4<<endl;
cout<<"----------------------split end--------------------"<<endl;
return 0;
}
测试输出
xz@xiaqiu:~/study/algorithm/c++/1/build$ ./test
----------------------size start--------------------
0
----------------------size end--------------------
----------------------insert start--------------------
10
9 8 7 6 5 4 3 2 1 0
----------------------insert end--------------------
----------------------get start--------------------
9 8 7 6 5 4 3 2 1 0
----------------------get end--------------------
----------------------erase start--------------------
9 8 7 6 5 4 3 2 1 0
10
3 2 1 0
4
----------------------erase end--------------------
----------------------push_back start--------------------
3 2 1 0
3 2 1 9 8 7 6 5 4 3 2 1 0 0
14
3 2 1 9 8 7 6 5 4 3 2 1 0 0 1000 1000 1000
17
----------------------push_back end--------------------
----------------------iterator start--------------------
3 2 1 9 8 7 6 5 4 3 2 1 0 0 1000 1000 1000
----------------------iterator end--------------------
----------------------setSize start--------------------
3 2 1 9 8 7 6 5 4 3 2 1 0 0 1000 1000 1000
17
3 2
2
----------------------setSize end--------------------
----------------------set start--------------------
3 2 0 1 2 3 4
7
10000
3 2 10000 1 2 3 4
7
----------------------set end--------------------
----------------------removeRange start--------------------
7
3 2 10000 1 2 3 4
3 2 3 4
4
lastNode = 4
----------------------removeRange end--------------------
----------------------lastIndexOf start--------------------
4
3 2 3 4
2
4
3 2 3 4
----------------------lastIndexOf end--------------------
----------------------operator[] start--------------------
3 2 3 4
4
3 2 3 4
4
3 2 3 4
0 1 2 3
----------------------operator[] end--------------------
----------------------operator== start--------------------
0 1 2 3
1
----------------------operator== end--------------------
----------------------operator!= start--------------------
0
----------------------operator!= end--------------------
----------------------leftShift start--------------------
0 1 2 3
2 3
----------------------leftShift end--------------------
----------------------reverse start--------------------
0 1 2 3
3
3 2 1 0
0
----------------------reverse end--------------------
----------------------meld1 start--------------------
2 3
3 2 1 0
2 3 3 2 1 0
0
6
----------------------meld1 end--------------------
----------------------meld2 start--------------------
2 3
3 2 1 0
2 3 3 2 1 0
0
6
----------------------meld2 end--------------------
----------------------split start--------------------
2 3 3 2 1 0
2 3 1
3 2 0
----------------------split end--------------------
xz@xiaqiu:~/study/algorithm/c++/1/build$
|