1 #include "linklist.h"
2 #include <iostream>
3 #include <climits>
4 #include <cstdlib>
5 #include <cstdio>
6
7 using namespace std;
8
9 int main(int argv, char **argc){
10
11 if(1){
12 LIST<int> mylist;
13 mylist.display();
14 // int size = mylist.size();
15 cout << "Size of the List is at the start is: " << mylist.size() << endl;
16 mylist.display();
17 mylist.insert(1);
18 cout << "Size of the List is: " << mylist.size() << endl;
19 mylist.display();
20 mylist.insert(1);
21 cout << "Size of the List is: " << mylist.size() << endl;
22 mylist.display();
23 mylist.insert(2);
24 cout << "Size of the List is: " << mylist.size() << endl;
25 mylist.display();
26 mylist.insert(4);
27 cout << "Size of the List is: " << mylist.size() << endl;
28 mylist.display();
29 mylist.insert(8);
30 cout << "Size of the List is: " << mylist.size() << endl;
31 mylist.display();
32 mylist.insert(16);
33 cout << "Size of the List is: " << mylist.size() << endl;
34 mylist.display();
35 mylist.remove_front();
36 cout << "Size of the List is: " << mylist.size() << endl;
37 mylist.display();
38 mylist.remove_all();
39 cout << "Size of the List is: " << mylist.size() << endl;
40 mylist.display();
41
42 cout << "****Testing find****" << endl;
43
44 int a = 0; int b = 1;int c;int index = 0; const int max = 50000;
45 mylist.insert(b);
46 cout << "Max Int is ==>" << INT_MAX << endl;
47 for(c=b+a;c < INT_MAX ; index++){
48 mylist.insert(c);
49 a = b;
50 b=c;
51 c=b+a;
52 if(c < b){
53 mylist.insert(b);
54 break; //This only happens when we get larger than an int
55 }
56 cout << "Size of the List is: " << mylist.size() << endl;
57 mylist.display();
58
59 }
60
61
62 NODE<int> * found = mylist.find(1836311903);
63 if(found != NULL)
64 cout << "Found ==>" << found->value() << " at " << found << endl;
65 else
66 cout << "1597 not found\n";
67
68 found = mylist.find(23);
69 if(found != NULL)
70 cout << "Found ==>" << found->value() << " at " << found << endl;
71 else
72 cout << "23 not found\n";
73 cout << "int b is ==>" << b << endl;
74 for (index = 0; index < max; index++){
75 found=mylist.find(index);
76 if(found != NULL)
77 cout << "Found ==>" << found->value() << " at " << found << endl;
78 //else
79 // cerr << index << " not found\n";
80 if (index > b) break;
81 }
82 mylist.remove_all();
83
84 cout << "*********** Test find_all ******************" << endl;
85 cout << "Create a huge link list of random numbers between 1-100\n";
86 int ran;
87 srand(12345);
88 for (index = 0; index < 50; index++){
89 ran = rand();
90 ran = ran % 101;
91 mylist.insert(ran);
92 // cout << "random ==>" << ran << endl;
93 }
94 mylist.insert(48);
95 mylist.insert(48);
96 mylist.insert(0);
97 mylist.insert(2);
98 mylist.insert(4);
99 mylist.insert(48);
100 mylist.insert(48);
101 mylist.insert(5);
102 mylist.insert(5);
103 mylist.insert(6);
104 mylist.insert(7);
105 mylist.insert(3);
106 mylist.insert(8);
107 mylist.insert(48);
108 mylist.insert(3);
109 mylist.insert(3);
110 mylist.insert(3);
111 mylist.insert(4);
112 mylist.insert(5);
113 mylist.insert(46);
114 mylist.insert(2);
115 mylist.insert(6);
116 mylist.insert(48);
117
118 cout << "List Size ==>" << mylist.size() << endl;
119 int cont48 = 0;
120 NODE<int> * tmp = mylist.find_all(48);
121 while(tmp != NULL){
122 //cout << "Found " << tmp->value() << " at ==>" << tmp << endl;
123 tmp = mylist.find_all(48, tmp);
124 cont48++;
125 }
126
127 cout << "******TESTING removing of an item****************" << endl;
128 cout << "Size is ==>" << mylist.size() << endl;
129 cout << "48 is in this list " << cont48 << " times\n";
130 // mylist.display();
131 tmp = mylist.find_all(48);
132
133 NODE<int> * tmp2 = tmp;
134 while(( tmp=mylist.find_all(48,tmp))){
135 // cout << "while::tmp not NULL\n";
136 // cout << "DELETING ==>" << tmp2 << " VALUE==> " << tmp->value() << endl;
137 mylist.remove_item(tmp2);
138 // cout << "Node is ==>" << tmp << endl;
139 tmp2 = tmp;
140 }
141 mylist.remove_item(tmp2);
142 // mylist.display();
143 cout << "Size is ==>" <<mylist.size() << endl;
144 // mylist.remove_all();
145 cout << "size + deletes = " << (mylist.size() + cont48) << endl;
146
147 cout << "*************TESTING SOME INSERTS********************************" << __LINE__ << endl;
148 mylist.insert(NULL,23);
149 mylist.insert(NULL,23);
150 mylist.insert(NULL,23);
151 // mylist.display();
152 //cout << "*************TESTING SOME INSERTS********************************" << __LINE__ << endl;
153 mylist.insert(23);
154 mylist.insert(23);
155 mylist.insert(23);
156 mylist.display();
157 //cout << "*************TESTING SOME INSERTS********************************" << __LINE__ << endl;
158 tmp = mylist.find(23);
159 cout << "*************found********************************" << __LINE__ << endl;
160 //cout << tmp << "\t" << tmp->value() << "*************TESTING SOME INSERTS********************************" << __LINE__ << endl;
161 mylist.insert(tmp,1111);
162 //cout << "*************TESTING SOME INSERTS********************************" << __LINE__ << endl;
163 // mylist.display();
164 tmp = mylist.find_all(23,tmp);
165 //cout << "*************found********************************" << __LINE__ << endl;
166 //cout << tmp << "\t" << tmp->value() << "*************TESTING SOME INSERTS********************************" << __LINE__ << endl;
167 mylist.insert(tmp,1111);
168 //cout << "*************TESTING SOME INSERTS********************************" << __LINE__ << endl;
169 // mylist.display();
170 while((tmp = mylist.find_all(23, tmp))){
171 //cout << "*************found********************************" << __LINE__ << endl;
172 //cout << tmp << "\t" << tmp->value() << "*************TESTING SOME INSERTS********************************" << __LINE__ << endl;
173 mylist.insert(tmp,1111);
174 //cout << tmp << "\t" << tmp->value() << "*************TESTING SOME INSERTS********************************" << __LINE__ << endl;
175 }
176
177
178 while((tmp = mylist.find_all(23, tmp))){
179 cout << "tmp==> "<< tmp << "\t" << "tmp-value()" << tmp->value() << endl;
180 cout << "*************WHile Loop TESTING SOME INSERTS findall********************************\n";
181 cout << tmp->value() << "\t" << (tmp->next())->value() << endl;
182 }
183
184 tmp=NULL;
185 while((tmp = mylist.find_all(1111, tmp))){
186 cout << "tmp==> "<< tmp << "\t" << "tmp-value()" << tmp->value() << endl;
187 // cout << "*************While Loop findall********************************\n";
188 cout << tmp->value() << "\t" << (tmp->next())->value() << endl;
189 }
190 mylist.display();
191
192 tmp=NULL;
193 mylist.insert(tmp,8888);
194 mylist.insert(8888);
195 cout << "inserted\n\n\n";
196 mylist.display();
197 while((tmp = mylist.find_all(8888, tmp))){
198 // cout << "tmp==> "<< tmp << "\t" << "tmp-value() " << tmp->value() << endl;
199 // cout << "*************While Loop TESTING findall********************************\n";
200 cout << tmp->value() << "\t" << (tmp->next())->value() << endl;
201 }
202 mylist.display();
203
204 }
205 LIST<int> * mylist = new LIST<int>;
206 mylist->display();
207 mylist->size();
208
209 return 0;
210 }