

If you don't know how to create lists see \hyperlink{eina_list_01_example_page}{Adding elements to Eina\+\_\+\+List}.


\begin{DoxyCodeInclude}
\textcolor{preprocessor}{#include <stdio.h>}
\textcolor{preprocessor}{#include <string.h>}
\textcolor{preprocessor}{#include <\hyperlink{Eina_8h}{Eina.h}>}

\textcolor{keywordtype}{int}
main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   (void)argc;
   (void)argv;
   \hyperlink{struct__Eina__List}{Eina\_List} *list = NULL, *other\_list = NULL;
   \hyperlink{struct__Eina__List}{Eina\_List} *l;
   \textcolor{keywordtype}{void} *data;
   \textcolor{keywordtype}{int} cmp\_result;
   \hyperlink{group__Eina__Types__Group_ga1b31ffcc0d46eed63a2381c5a011b486}{Eina\_Compare\_Cb} cmp\_func = (\hyperlink{group__Eina__Types__Group_ga1b31ffcc0d46eed63a2381c5a011b486}{Eina\_Compare\_Cb})strcmp;

   \hyperlink{group__Eina__Main__Group_gabf448ada5bc81a07342b66c6f818ee5e}{eina\_init}();

   list = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(list, \textcolor{stringliteral}{"starbuck"});
   list = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(list, \textcolor{stringliteral}{"appolo"});
   list = \hyperlink{group__Eina__List__Group_ga92ec14d1a1040a361c4d8cd0ab7b0ecc}{eina\_list\_append}(list, \textcolor{stringliteral}{"boomer"});

\end{DoxyCodeInclude}
 This is the code we have already seen to create a list. Now if we need to search the list we can do it like this\+: 
\begin{DoxyCodeInclude}

   data = \hyperlink{group__Eina__List__Group_ga2c093bfd321df8f286fcfeb3d13d675f}{eina\_list\_search\_unsorted}(list, cmp\_func, \textcolor{stringliteral}{"boomer"});
   l = \hyperlink{group__Eina__List__Group_ga326ba1ce720272160559fcca1abb100d}{eina\_list\_search\_unsorted\_list}(list, cmp\_func, \textcolor{stringliteral}{"boomer"});
   \textcolor{keywordflow}{if} (l->\hyperlink{struct__Eina__List_a043e22d601d3a0504f30255a43a25e7a}{data} != data)
     \textcolor{keywordflow}{return} 1;

\end{DoxyCodeInclude}


However if searching the list multiple times it probably is better to sort the list since the sorted\+\_\+search functions are much faster\+: 
\begin{DoxyCodeInclude}

   list = \hyperlink{group__Eina__List__Group_gaa634ce6790e626fd057ecdcfdc841d47}{eina\_list\_sort}(list, 0, cmp\_func);

   data = \hyperlink{group__Eina__List__Group_gae18055abaafef1714bd9f2fd3fd0cc45}{eina\_list\_search\_sorted}(list, cmp\_func, \textcolor{stringliteral}{"starbuck"});
   l = \hyperlink{group__Eina__List__Group_ga6a0564d119664930b3a41657c1551e09}{eina\_list\_search\_sorted\_list}(list, cmp\_func, \textcolor{stringliteral}{"starbuck"});
   \textcolor{keywordflow}{if} (l->\hyperlink{struct__Eina__List_a043e22d601d3a0504f30255a43a25e7a}{data} != data)
     \textcolor{keywordflow}{return} 1;

\end{DoxyCodeInclude}


Once the list is sorted it's not a good idea to use append/prepend functions since that would add the element in the wrong place, instead elements should be added with \hyperlink{group__Eina__List__Group_ga00740e04bfb71ad5c9ac145f766de3a4}{eina\+\_\+list\+\_\+sorted\+\_\+insert()}\+: 
\begin{DoxyCodeInclude}

   list = \hyperlink{group__Eina__List__Group_ga00740e04bfb71ad5c9ac145f766de3a4}{eina\_list\_sorted\_insert}(list, cmp\_func, \textcolor{stringliteral}{"helo"});

\end{DoxyCodeInclude}


A noteworthy use case is adding an element to a list only if it doesn't exist already, this can accomplished by searching for the element that is closest to what is being added, and if that doesn't match add\+: 
\begin{DoxyCodeInclude}

   l = \hyperlink{group__Eina__List__Group_ga44af3419fd1f66ffefc4998e54c4ca70}{eina\_list\_search\_sorted\_near\_list}(list, cmp\_func, \textcolor{stringliteral}{"hera"}, &
      cmp\_result);
   \textcolor{keywordflow}{if} (cmp\_result > 0)
     list = \hyperlink{group__Eina__List__Group_ga03a77b1579ee83bcab4bc3d67375d4b1}{eina\_list\_prepend\_relative\_list}(list, \textcolor{stringliteral}{"hera"}, l);
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (cmp\_result < 0)
     list = \hyperlink{group__Eina__List__Group_gafa705d4483487e53d1be93a30e43c66d}{eina\_list\_append\_relative\_list}(list, \textcolor{stringliteral}{"hera"}, l);

\end{DoxyCodeInclude}
 \begin{DoxyNote}{Note}
\hyperlink{group__Eina__List__Group_ga44af3419fd1f66ffefc4998e54c4ca70}{eina\+\_\+list\+\_\+search\+\_\+sorted\+\_\+near\+\_\+list()} will tell you not only the nearest node to what was searched for but how it compares to your term, this way it is easy to know if you have to add before or after that node.
\end{DoxyNote}
It is sometimes useful to get a portion of the list as another list, here we take every element that comes after \char`\"{}boomer\char`\"{} and split it into \char`\"{}other\+\_\+list\char`\"{}\+: 
\begin{DoxyCodeInclude}

   l = \hyperlink{group__Eina__List__Group_ga6a0564d119664930b3a41657c1551e09}{eina\_list\_search\_sorted\_list}(list, cmp\_func, \textcolor{stringliteral}{"boomer"});
   list = \hyperlink{group__Eina__List__Group_gaf45625cf0f450aae2a4e949539b22374}{eina\_list\_split\_list}(list, l, &other\_list);

\end{DoxyCodeInclude}


It is also possible to add entire lists of elements using \hyperlink{group__Eina__List__Group_ga66747ee5bad3c35ea268385f6c5e174b}{eina\+\_\+list\+\_\+sorted\+\_\+merge()}\+: 
\begin{DoxyCodeInclude}

   other\_list = \hyperlink{group__Eina__List__Group_gaa634ce6790e626fd057ecdcfdc841d47}{eina\_list\_sort}(other\_list, 0, cmp\_func);

   list = \hyperlink{group__Eina__List__Group_ga66747ee5bad3c35ea268385f6c5e174b}{eina\_list\_sorted\_merge}(list, other\_list, cmp\_func);

\end{DoxyCodeInclude}


And as always release memory and shutdown eina before ending\+: 
\begin{DoxyCodeInclude}

   \hyperlink{group__Eina__List__Group_ga608bd2fbf06293a1b794648990703ab4}{eina\_list\_free}(list);

   \hyperlink{group__Eina__Main__Group_ga6741fcaba116e31e96ce14dcfa03f568}{eina\_shutdown}();

   \textcolor{keywordflow}{return} 0;
\}

\end{DoxyCodeInclude}


The full source code can be found on the examples folder on the \hyperlink{eina_list_02_c}{eina\+\_\+list\+\_\+02.c} file. 