1 /*
  2  * =====================================================================================
  3  *
  4  *       Filename:  test_del.cpp
  5  *
  6  *    Description:  Testing Double Deletes
  7  *
  8  *        Version:  1.0
  9  *        Created:  04/02/2011 05:12:24 PM
 10  *       Revision:  none
 11  *       Compiler:  gcc
 12  *
 13  *         Author:  YOUR NAME Ruben Safir,
 14  *        Company:  NYLXS
 15  *
 16  * =====================================================================================
 17  */
 18
 19
 20
 21 #ifndef  LINKLIST
 22 #define LINKLIST
 23 #include        "linklist.h"
 24 #endif     /* -----  not LINKLIST  ----- */
 25
 26 #include        <iostream>
 27 #include        <fstream>
 28 #include        <climits>
 29 #include        <stdlib.h>
 30
 31 /* 
 32  * ===  FUNCTION  ======================================================================
 33  *         Name:  main
 34  *  Description:  
 35  * =====================================================================================
 36  */
 37
 38
 39 chainlist::List<int>& creating_int_list();
 40 void find_all_examples(chainlist::List<int>&, int);
 41
 42
 43 int main ( int argc, char *argv[] )
 44 {
 45
 46    srand(12345);
 47    int i,j;
 48    chainlist::List<int> outside = creating_int_list();
 49
 50    chainlist::List<int> a[100];
 51    for( i=0; i < 100; ++i){
 52       std::cout << "CREATING LIST for ARRAY -------------------------------\n";
 53       a[i] = creating_int_list();
 54    }
 55
 56    for( i=0; i < 100; ++i){
 57       std::cout << "NEW SEARCH -------------------------------\n";
 58       for(j=0;j < 100; j++){
 59          find_all_examples(a[i], j);
 60       }
 61    }
 62
 63    for( i=0; i < 100; ++i){
 64       std::cout << "Removing Nodes -------------------------------\n";
 65       a[i].remove_all();
 66    }
 67
 68
 69    std::cout << "**************DONE WITH ARRAY SEARCHES***************\n";
 70
 71    std::cout << "Size of outside List " << sizeof(outside) << std::endl;
 72    std::cout << "Size of outside Node " << sizeof*(outside.cursor())  << std::endl;
 73 //   outside.display();
 74    find_all_examples(outside, 4);
 75
 76    outside.find_value(4);
 77
 78
 79    std::cout << "****************************************OUTSIDE**************************************************" << std::endl;
 80   
 81    chainlist::Node<int> * found = outside.cursor();
 82    if(found){
 83       std::cout << "Found first value ==> '" << *found->value() << "' at node =='" << outside.cursor() << std::endl;
 84       found = &(outside.find_next_value(4, *found));
 85       while( found ){
 86          std::cout << "Found next value ==> '" << *(found->value()) << "' at node =='" << outside.cursor() << std::endl;
 87          found = &(outside.find_next_value(4, *found));
 88       }
 89    }
 90
 91
 92    std::cout << "****************************************END**************************************************" << std::endl;
 93    return EXIT_SUCCESS;
 94 }                               /* ----------  end of function main  ---------- */
 95
 96
 97 chainlist::List<int> &creating_int_list(){
 98    // chainlist::List<int>  set = new chainlist::List<int>;
 99    chainlist::List<int> * set = new chainlist::List<int>;
100    int ran;
101    for(int i = 0; i < 100; ++i){
102       ran=rand();
103       set->insert(ran % 100);
104    }
105    set->display();
106    return *set;
107 }
108
109 void find_all_examples ( chainlist::List<int>& glob, int search_value )
110 {
111    std::cout << "Searching for " <<  search_value << " in list \n" ;
112    glob.display();
113    glob.find_value(search_value);
114    chainlist::Node<int> * found = glob.cursor();
115    if(found){
116       std::cout << "Found first value ==> '" << *found->value() << "' at node =='" << glob.cursor() << std::endl;
117       found = &(glob.find_next_value(search_value, *found));
118       while( found ){
119          std::cout << "Found next value ==> '" << *(found->value()) << "' at node =='" << glob.cursor() << std::endl;
120          found = &(glob.find_next_value(search_value, *found));
121       }
122    }
123
124
125    return ;
126 }