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 #include "stats.h"
25 #endif /* ----- not LINKLIST ----- */
26
27 #include <iostream>
28 #include <fstream>
29 #include <climits>
30 #include <stdlib.h>
31 #include <iomanip>
32
33 chainlist::List<int>* creating_int_list();
34 void find_all_examples(chainlist::List<int>*&, int);
35
36
37
38
39
40 chainlist::List<stats::Distribution<int> > * tally; //a list of distribution talleys in global space
41
42
43
44 int main ( int argc, char *argv[] ){
45
46 tally = new chainlist::List<stats::Distribution<int> >;
47
48 srand(12345);
49 //quick test of the order
50 chainlist::List<char> * alefbais = new chainlist::List<char>;
51 alefbais->insert('a');
52 alefbais->insert('b');
53 alefbais->insert('c');
54 alefbais->insert('d');
55 alefbais->insert('e');
56 alefbais->insert('f');
57 alefbais->insert('g');
58 alefbais->insert('h');
59 alefbais->insert('i');
60 alefbais->insert('j');
61 alefbais->display();
62 delete alefbais;
63
64 chainlist::List<char> alefbais2;
65 alefbais2.insert('a');
66 alefbais2.insert('b');
67 alefbais2.insert('c');
68 alefbais2.insert('d');
69 alefbais2.insert('e');
70 alefbais2.insert('f');
71 alefbais2.insert('g');
72 alefbais2.insert('h');
73 alefbais2.insert('i');
74 alefbais2.insert('j');
75 alefbais2.insert();
76 alefbais2.insert();
77 alefbais2.find_value('j');
78 // alefbais2.find_value('z');
79 alefbais2.cursor(alefbais2.cursor()->next());
80 alefbais2.cursor()->value('k');
81 alefbais2.cursor(alefbais2.cursor()->next());
82 alefbais2.cursor()->value('l');
83 alefbais2.find_value('z');
84 alefbais2.display();
85
86
87
88 {
89 unsigned int i,j;
90 chainlist::List<chainlist::List<int> * > a;
91 for( i=0; i < 1000; ++i){
92 std::cout << "CREATING LIST for ARRAY -------------------------------\n";
93 a[i] = creating_int_list();
94 a[i]->sort(*(a[i]));
95 std::cout << "Sorted List" << std::endl;
96 // a[i]->display();
97 std::cout << std::endl;
98 }
99 a.sort(a);
100 a.display();
101
102
103 for( i=0; i < 1000; ++i){
104 std::cout << "NEW SEARCH in index " << i << "-------------------------------\n";
105 stats::take_tally<int>(a[i], tally);
106 for(j=0;j < 100; j++){
107 std::cout << "NEW SEARCH in value " << j << "-------------------------------\n";
108 find_all_examples(a[i], j);
109 }
110 }
111 std::cout << "HELLO WORLD" << std::endl;
112 std::cout << "The mean population occurance for any number is ==> " << stats::mean_list(tally) << std::endl;
113 std::cout << "The stanard deviation is ==> " << stats::stddev(tally) << std::endl;
114
115 tally->display();
116
117 for( i=0; i < 100; ++i){
118 std::cout << "NEW SEARCH for 6 -------------------------------\n";
119 a[i]->find_value(6);
120 if(a[i]->cursor() ){
121 std::cout << "Replacing 6 wth 1000000 " << a[i]->cursor() << " is the cursor " << std::endl;
122 *(a[i]->cursor()->value()) = 1000000;
123 }
124 while(a[i]->cursor() ){
125 a[i]->find_next_value(6,a[i]->cursor());
126 if(a[i]->cursor() ){
127 std::cout << "Replacing 6 wth 1000000 " << a[i]->cursor() << " is the cursor " << std::endl;
128 *(a[i]->cursor()->value()) = 1000000;
129 }
130 }
131 a[i]->display();
132 }
133
134 for( i=0; i<100; ++i){
135 a[i]->display();
136 }
137
138 for( i=0; i < 100; ++i){
139 std::cout << "Removing Nodes -------------------------------\n";
140 a[i]->remove_all();
141 }
142 }
143
144 std::cout << "**************DONE WITH ARRAY SEARCHES***************\n";
145 {
146 chainlist::List<int> * outside = creating_int_list();
147
148 std::cout << "Size of outside List " << sizeof(outside) << std::endl;
149 std::cout << "Size of outside Node " << sizeof*(outside->cursor()) << std::endl;
150 // outside.display();
151 find_all_examples(outside, 4);
152
153 outside->find_value(4);
154
155
156 std::cout << "****************************************OUTSIDE**************************************************" << std::endl;
157
158 chainlist::Node<int> * found = outside->cursor();
159 if(found){
160 std::cout << "Found first value ==> '" << *found->value() << "' at node =='" << outside->cursor() << std::endl;
161 found = outside->find_next_value(4, found);
162 while( found ){
163 std::cout << "Found next value ==> '" << *(found->value()) << "' at node =='" << outside->cursor() << std::endl;
164 found = outside->find_next_value(4, found);
165 }
166 }
167
168 delete outside;
169 std::cout << "****************************************END**************************************************" << std::endl;
170 }
171 return EXIT_SUCCESS;
172 } /* ---------- end of function main ---------- */
173
174
175 chainlist::List<int> * creating_int_list(){
176 // chainlist::List<int> set = new chainlist::List<int>;
177 chainlist::List<int> * set = new chainlist::List<int>;
178 int ran;
179 for(int i = 0; i < 100; ++i){
180 ran=rand();
181 set->insert(ran % 100);
182 }
183 set->display();
184 return set;
185 }
186
187 void find_all_examples ( chainlist::List<int>* & glob, int search_value )
188 {
189 std::cout << "Searching for " << search_value << " in list \n" ;
190 glob->display();
191 glob->find_value(search_value);
192 chainlist::Node<int> * found = glob->cursor();
193 if(found){
194 std::cout << "Found first value ==> '" << *found->value() << "' at node =='" << glob->cursor() << std::endl;
195 found = glob->find_next_value(search_value, found);
196 while( found ){
197 std::cout << "Found next value ==> '" << *(found->value()) << "' at node =='" << glob->cursor() << std::endl;
198 found = glob->find_next_value(search_value, found);
199 }
200 }
201
202
203 return ;
204 }
205