Tutorialspoint

C++ Forward list Library forward list() function

#include <iostream>
#include <forward_list>

using namespace std;

int main(void) {
   forward_list<int> fl;

   if (fl.empty())
      cout << "Forward list contains zero elements." << endl;

   return 0;
}

C++ List Library swap() function

#include <iostream>
#include <list>

using namespace std;

int main(void) {
   list<int> l1 = {1, 2, 3};
   list<int> l2 = {10, 20, 30, 40, 50};

   cout << "List l1 contains following elements before swap operation" << endl;
   for (auto it = l1.begin(); it != l1.end(); ++it)
      cout << *it << endl;

   cout << "List l2 contains following elements before swap operation" << endl;
   for (auto it = l2.begin(); it != l2.end(); ++it)
      cout << *it << endl;

   swap(l1, l2);

   cout << "List l1 contains following elements after swap operation" << endl;
   for (auto it = l1.begin(); it != l1.end(); ++it)
      cout << *it << endl;

   cout << "List l2 contains following elements after swap operation" << endl;
   for (auto it = l2.begin(); it != l2.end(); ++it)
      cout << *it << endl;

   return 0;
}

C++ List Library operator greater than or equal to function

#include <iostream>
#include <list>

using namespace std;

int main(void) {
   list<int> l1 = {1, 2, 3};
   list<int> l2 = {1, 2, 3};

   if (l1 >= l2)
      cout << "List l1 is greater that or equal to l2" << endl;

   l1.pop_back();

   if (!(l1 >= l2))
      cout << "List l1 is not greater that or equal to l2" << endl;

   return 0;
}

C++ List Library operator greater than function

#include <iostream>
#include <list>

using namespace std;

int main(void) {
   list<int> l1 = {1, 2, 3, 4};
   list<int> l2 = {1, 2, 3};

   if (l1 > l2)
      cout << "List l1 is greater that l2" << endl;

   l1.pop_back();

   if (!(l1 > l2))
      cout << "List l1 is not greater that l2" << endl;

   return 0;
}

C++ List Library operator less than or equal to function

#include <iostream>
#include <list>

using namespace std;

int main(void) {
   list<int> l1 = {1, 2, 3};
   list<int> l2 = {1, 2, 3};

   if (l1 <= l2)
      cout << "List l1 is less that or equal to l2" << endl;

   l2.pop_back();

   if (!(l1 <= l2))
      cout << "List l1 is not less that or equal to l2" << endl;

   return 0;
}

C++ List Library operator less than function

#include <iostream>
#include <list>

using namespace std;

int main(void) {
   list<int> l1 = {1, 2, 3};
   list<int> l2 = {1, 2, 3, 4};

   if (l1 < l2)
      cout << "List l1 is less that l2" << endl;

   l2.pop_back();

   if (!(l1 < l2))
      cout << "List l1 is not less that l2" << endl;

   return 0;
}

C++ List Library operator not equal to function

#include <iostream>
#include <list>

using namespace std;

int main(void) {
   list<int> l1 = {1, 2, 3};
   list<int> l2 = {1, 2, 3, 4};

   if (l1 != l2)
      cout << "List l1 and l2 are not equal" << endl;

   l2.pop_back();

   if (!(l1 != l2))
      cout << "List l1 and l2 are equal" << endl;

   return 0;
}

Clojure Maps dissoc

(ns clojure.examples.example
   (:gen-class))
(defn example []
   (def demokeys (hash-map "z" "1" "b" "2" "a" "3"))
   (println (dissoc demokeys "b")))
(example)

C++ List Library operator equal to function

#include <iostream>
#include <list>

using namespace std;

int main(void) {
   list<int> l1 = {1, 2, 3};
   list<int> l2 = {1, 2, 3};

   if (l1 == l2)
      cout << "List l1 and l2 are equal" << endl;

   l1.push_back(4);

   if (!(l1 == l2))
      cout << "List l1 and l2 are not equal" << endl;

   return 0;
}

C++ List Library unique() function

#include <iostream>
#include <list>

using namespace std;

/* Ignore sign of the value */
bool pred(int a, int b) {
   return (abs(a) == abs(b));
}

int main(void) {
   list <int> l = {1, -1, -1, -1, 2, 2, -2, -2, 3, -4, 4, -5, -5, 5};

   cout << "List elements before unique operation" << endl;

   for (auto it = l.begin(); it != l.end(); ++it)
      cout << *it << endl;

   /* Ignore sign of the value */
   l.unique(pred);

   cout << "List elements after unique operation" << endl;

   for (auto it = l.begin(); it != l.end(); ++it)
      cout << *it << endl;

   return 0;
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.