Ejemplo n.º 1
0
void SwapTwoLists::run()
{
    SList newList;
    SList otherList;
    std::string str1 = "foo";
    std::string str2 = "bar";
    std::string str3 = "baz";
    std::string str4 = "far";
    std::string str5 = "faz";
    newList.push_front(str1);
    newList.push_front(str2);
    newList.push_front(str3);
    otherList.push_front(str4);
    otherList.push_front(str5);
    newList.swap(otherList);

    checkEquals(newList.front(), str5);
    newList.pop_front();
    checkEquals(newList.front(), str4);

    checkEquals(otherList.front(), str3);
    otherList.pop_front();
    checkEquals(otherList.front(), str2);
    otherList.pop_front();
    checkEquals(otherList.front(), str1);
}
Ejemplo n.º 2
0
 void SList::reverse() {
   SList tmp;
   Elem *tmp_elem = front;
   while(tmp_elem) {
     tmp.push_front(tmp_elem->get_contents());
     tmp_elem = tmp_elem->next;
   }
   tmp.swap(*this);
 }
Ejemplo n.º 3
0
void test_swap(Test* test)
{
	SList *list = new SList("hello","world");
	SList *list_ = new SList("hei","maailma");
	
	list->swap((*list_));
	std::cout<<(*list)<<std::endl;
	std::cout<<(*list_)<<std::endl;
	delete list;
	delete list_;
}