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 test_push_front(Test* test)
{
	std::string s("hello");
	SList* list = new SList("hello","word");
	list->push_front(s);
	std::string act=list->get_first()->get_stringi();
	test->equals(act,s);
	delete list;
}
Ejemplo n.º 3
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.º 4
0
void testSList()
{
  SList list;

  list.push_front("Alice");
  list.push_front("Bob");
  list.push_front("Copernicus");
  
  for (SList::ConstIterator cit = list.begin(); cit != list.end(); ++cit) {
    std::cout << *cit << std::endl;
  }
  std::cout << std::endl;

  for (SList::Iterator it = list.begin(); it != list.end(); ++it) {
    std::cout << *it << std::endl;
  }
  std::cout << std::endl;
}
Ejemplo n.º 5
0
int main()
{
        /* string list */
        SList<string> strlist;
        strlist.push_back("syed");
        strlist.push_back("ahsan");
        strlist.push_front("ishtiaque");
        strlist.print();
        cout << strlist.is_present("ahsan") << endl;
        strlist.push_back("ahsan");
        strlist.print();
        strlist.delete_first("ahsan");
        strlist.print();
        strlist.push_back("ahsan");
        strlist.print();
        strlist.delete_all("ahsan");
        strlist.print();


        return 0;
}