44 return (
static_cast<Dnode<int>*
>(p)->get_data() <
50int main(
int argc,
char *argv[])
55 try { n = stoi(argv[1]); }
56 catch (...) { n = 1000; }
62 cerr <<
"Error: n must be a positive integer." << endl;
66 unsigned int t = std::time(0);
70 try { t =
static_cast<unsigned int>(stoul(argv[2])); }
71 catch (...) { t = std::time(0); }
76 cout << argv[0] <<
" " << n <<
" " << t << endl;
80 for (
int i = 0; i < n; ++i)
82 int value = 1 + (int) (1.0 * n * (rand() / (RAND_MAX + 1.0)));
88 cout << it.get_curr()->get_data() <<
" ";
92 if (Aleph::random_search<int, Cmp>(list, n/2) != NULL)
93 cout << n/2 <<
" se encuentra en la lista" << endl;
95 cout << n/2 <<
" no se encuentra en la lista" << endl;
101 cout << n/2 <<
" se encuentra en la lista" << endl;
103 cout << n/2 <<
" no se encuentra en la lista" << endl;
105 assert(list.
check());
108 cout << it.get_curr()->get_data() <<
" ";
111 assert(list.
check());
113 Dnode<int> * ptr = Aleph::random_select <int> (list, n/2);
115 cout <<
"El elemento " << n/2 <<
" es: " << ptr->
get_data() << endl;
size_t size_t int32_t value
bool has_curr() const noexcept
Return true if the iterator has current item.
Doubly linked circular list node.
void remove_all_and_delete() noexcept
Remove and free memory for all the items of list.
void append(Dlink *node) noexcept
Insert node before this.
bool check()
Return true if the list is consistent.
Iterator on a list of Dnode objects.
Node belonging to a double circular linked list with header node.
T & get_data() noexcept
Return a modifiable reference to the data contained in the node.
long random_search(T *a, const T &x, const long l, const long r, const Compare &cmp=Compare())
Random search for an element in an array.
bool operator()(Dlink *p, Dlink *q) const
Comprehensive sorting algorithms and search utilities for Aleph-w.