-
Notifications
You must be signed in to change notification settings - Fork 8
/
ParseTree.cpp
792 lines (713 loc) · 23.5 KB
/
ParseTree.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
/////////////////////////////////////////////////////////////////////////////
//Title: ParseTree.cpp
//Author: Kristina Klinkner
//Date: July 23, 2003
//Description: Class for ParseTree used to store all strings and their
// frequency of occurence up to
// a set maximum length which appear in a given data file.
// For use with CSSR.
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 Kristina Klinkner
// This file is part of CSSR
//
// CSSR is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// CSSR is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with CSSR; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//////////////////////////////////////////////////////////////////////////////
#include "ParseTree.h"
///////////////////////////////////////////////////////////////////////////
// Function: ParseTree::MakeAlphaHash
// Purpose: creates a hash table which returns the index of an alphabet
// symbol
// In Params: none
// Out Params: none
// In/Out Params: none
// Pre- Cond: alphabet file has been read in
// Post-Cond: hash table contains all alpha info and has returned table
// to calling function
//////////////////////////////////////////////////////////////////////////
HashTable2* ParseTree::MakeAlphaHash()
{
char* symbol = new char[2];
symbol[1] = '\0';
for(int k = 0; k < m_alphaSize; k++)
{
symbol[0] = m_alpha[k];
m_alphaHash->Insert(symbol,k);
}
delete symbol;
return m_alphaHash;
}
///////////////////////////////////////////////////////////////////////////
// Function: ParseTree::Insert
// Purpose: inserts a new string into the Parse Tree
// In Params: the string to insert and the root of the current subtree
// Out Params: none
// In/Out Params: none
// Pre- Cond: none
// Post-Cond: tree exists with at least one string
//////////////////////////////////////////////////////////////////////////
void ParseTree::Insert(char string[], TreeNode*& root)
{
//base case, we are done with string
if(strlen(string) < 1)
return;
//a node does not exist for this substring yet
if(root == NULL)
{
//add a node
root = new TreeNode;
root->m_symbol = string[0];
root->m_count++;
//make recursive call with remaining string
Insert(&(string[1]), root->m_child);
}
//this substring already exists
else if(root->m_symbol==string[0])
{
//increase the count of the substring
root->m_count++;
//and make recursive call
Insert(&(string[1]), root->m_child);
}
//the substring may be in a sibling node
else if(root->m_symbol!=string[0])
{
TreeNode** temp;
temp = &root;
while(*temp!=NULL && (*temp)->m_symbol!= string[0])
temp = &((*temp)->m_sibling);
//or if not, it should be added there
if(*temp == NULL)
{
*temp = new TreeNode;
(*temp)->m_symbol = string[0];
}
(*temp)->m_count++;
//recursive call made with sibling node
Insert(&(string[1]), (*temp)->m_child);
}
}
///////////////////////////////////////////////////////////////////////////
// Function: ParseTree::RemoveTree
// Purpose: deletes the Parse Tree
// In Params: the root of the current subtree
// Out Params: none
// In/Out Params: none
// Pre- Cond: tree exists
// Post-Cond: tree has been deleted
//////////////////////////////////////////////////////////////////////////
void ParseTree::RemoveTree(TreeNode*& root)
{
TreeNode* temp;
if(root!= NULL)
{
while(root!=NULL)
{
temp = root;
RemoveTree(root->m_child);
root = root->m_sibling;
delete temp;
}
}
}
///////////////////////////////////////////////////////////////////////////
// Function: ParseTree::FindStrings
// Purpose: wrapper function for protected version of FindStrings
// In Params: the length of strings looked for
// Out Params: the growable array of strings
// In/Out Params: none
// Pre- Cond: tree exists
// Post-Cond: strings of length 'length' have been put in an array
// along with the counts of their children strings
//////////////////////////////////////////////////////////////////////////
void ParseTree::FindStrings(int length, G_Array* array)
{
char* parentString = '\0';
FindStrings(m_root, length, parentString, array);
return;
}
///////////////////////////////////////////////////////////////////////////
// Function: ParseTree::DecStringCount
// Purpose: wrapper function for protected version of DecStringCount
// In Params: the string to decrement
// Out Params: none
// In/Out Params: none
// Pre- Cond: tree exists
// Post-Cond: occurences of string and substrings have been decremented
//////////////////////////////////////////////////////////////////////////
void ParseTree::DecStringCount(char* stringToDec)
{
DecStringCount(stringToDec, m_root);
}
///////////////////////////////////////////////////////////////////////////
// Function: ParseTree::FindStrings
// Purpose: collects all strings of length 'length' in an array
// In Params: root of the tree, length of strings sought, a string to hold
// Out Params: the growable array of strings
// In/Out Params: the parent symbols as tree is traversed
// Pre- Cond: tree exists
// Post-Cond: strings of length 'length' have been put in an array
// along with the counts of their children strings
//////////////////////////////////////////////////////////////////////////
void ParseTree::FindStrings(TreeNode* root, int length, char* parentString,
G_Array* array)
{
//if strings do not exist at this branch return
if(root == NULL)
return;
//when at the desired level of the tree cycle thru list of siblings and add
//each symbol to parent string
else if(length < 2)
{
//determine length of parentString
int stringLength = 0;
if(parentString != '\0')
stringLength = strlen(parentString);
char* tempString = new char[stringLength +2];
TreeNode* tempChild;
char* symbol = new char[2];
int* counts = new int[m_alphaSize];
while(root!= NULL)
{
//copy over any parent string information
symbol[0] = root->m_symbol;
symbol[1] = '\0';
if(stringLength != 0)
{
strcpy(tempString, parentString);
strcat(tempString, symbol);
}
else
strcpy(tempString, symbol);
//initialize array
for(int i = 0; i< m_alphaSize;i++)
counts[i] = 0;
//add counts of each child node to array
//in order of alphabet symbols
tempChild = root->m_child;
while (tempChild !=NULL)
{
for(int k=0; k < m_alphaSize; k++)
{
if(m_alpha[k] == tempChild->m_symbol)
counts[k] = tempChild->m_count;
}
tempChild = tempChild->m_sibling;
}
//input each in growable array class
array->Insert(tempString, counts, m_alphaSize);
root = root->m_sibling;
}
//free memory
delete[] tempString;
delete[] symbol;
delete[] counts;
return;
}
//check correct level in all possible branches
else
{
//determine length of parentString
int stringLength2 = 0;
if(parentString != '\0')
stringLength2 = strlen(parentString);
char* newParent = new char[stringLength2 +2];
char* symbol2 = new char[2];
while(root!= NULL)
{
//attach present symbol to parent string
symbol2[0] = root->m_symbol;
symbol2[1] = '\0';
if(stringLength2 != 0)
{
strcpy(newParent, parentString);
strcat(newParent, symbol2);
}
else
strcpy(newParent,symbol2);
//call each sibling recursively
FindStrings(root->m_child, length - 1, newParent, array);
root = root->m_sibling;
}
//free memory
delete[] newParent;
delete[] symbol2;
return;
}
}
///////////////////////////////////////////////////////////////////////////
// Function: ParseTree::CreateTree
// Purpose: reads data and stores all strings of up to maximum length
// in tree
// In Params: none
// Out Params: none
// In/Out Params: none
// Pre- Cond: tree is empty
// Post-Cond: tree is full
//////////////////////////////////////////////////////////////////////////
void ParseTree::FillTree()
{
//look at futures of 1 for maximum
//length strings
int max_length = m_maxLength + 1;
char* string = new char[max_length+1];
int i, j, k;
for(i = 0; i <= (m_dataSize - max_length); i++)
{
for(k=0; k < max_length; k++)
string[k] = m_data[k+i];
string[k] = '\0';
Insert(string);
}
for(k=0; k< max_length;k++,i++)
{
for(j =0; j <max_length-k;j++)
string[j] = m_data[j+i];
string[j] = '\0';
Insert(string);
}
}
//////////////////////////////////////////////////////////////////////////
// Function: ParseTree::GetDataInput
// Purpose: reads in the data string
// In Params: the data input filename
// Out Params: none
// In/Out Params: none
// Pre- Cond: Filenames must have been read in at command line,
// size of alphabet file must be smaller than data file
// Post-Cond: Data info in ParseTree is initialized
//////////////////////////////////////////////////////////////////////////
void ParseTree::GetDataInput(char dataFile[])
{
int size;
int offset = 1;
//create file stream
ifstream inData(dataFile, ios::in);
//open data file, if unsuccessful set boolean return value
if(!inData.is_open())
{
cerr << " the data file cannot be opened " << endl;
exit(1);
}
//otherwise read in data until end of file
else
{
inData.seekg(0,ios::end);
size = inData.tellg();
inData.seekg(0,ios::beg);
m_data = new char[size + 1];
inData.get(m_data,size + 1, '\0');
if(m_data[size - 2] == '\n')
offset = 2;
else if(m_data[size - 1] == '\n')
offset =1;
else if(isalnum(m_data[size - 1]))
offset = 0;
m_data[size - offset] = '\0';
inData.close();
m_dataSize = strlen(m_data);
m_adjustedDataSize = (m_dataSize - (m_maxLength - 1));
}
}
//////////////////////////////////////////////////////////////////////////
// Function: ParseTree::GetAlphaInput
// Purpose: reads in the alphabet file
// In Params: the alphabet input filename
// Out Params: none
// In/Out Params: none
// Pre- Cond: Filenames must have been read in at command line,
// size of alphabet file must be smaller than data file
// Post-Cond: Alphabet info in ParseTree is initialized
//////////////////////////////////////////////////////////////////////////
void ParseTree::GetAlphaInput(char alphaFile[])
{
int size;
int offset = 1;
//create file streams
ifstream inAlpha(alphaFile, ios::in);
//open alphabet file, if unsuccessful set boolean return value
if(!inAlpha.is_open())
{
cerr << " the alphabet file cannot be opened " << endl;
exit(1);
}
//otherwise read in data until end of file
else
{
inAlpha.seekg(0,ios::end);
size = inAlpha.tellg();
inAlpha.seekg(0,ios::beg);
m_alpha = new char[size + 1];
inAlpha.get(m_alpha,size + 1,'\0');
if(m_alpha[size - 2] == '\n')
offset = 2;
else if(m_alpha[size - 1] == '\n')
offset =1;
else if(isalnum(m_data[size - 1]))
offset = 0;
m_alpha[size - offset] = '\0';
inAlpha.close();
m_alphaSize = strlen(m_alpha);
}
}
//////////////////////////////////////////////////////////////////////////
// Function: ParseTree::CheckAlphaInput
// Purpose: checks the alphabet string for spaces or nonsense
// In Params: ParseTree class variables --- m_alpha, m_alphaSize
// Out Params: none
// In/Out Params: none
// Pre- Cond: Alpha file has been read in
// Post-Cond: Alphabet information in ParseTree class is valid
//////////////////////////////////////////////////////////////////////////
void ParseTree::CheckAlphaInput()
{
char* tempAlpha = new char[m_alphaSize];
char seps[] = " ,\t\n\r";
char* token;
//first, remove white spaces, tabs, or endlines
token = strtok(m_alpha, seps );
strcpy(tempAlpha,token);
while( token != NULL )
{
/* Get next token: */
token = strtok(NULL, seps );
if(token !=NULL)
strcat(tempAlpha,token);
}
//make necessary adjustments to alphabet and size
delete m_alpha;
m_alpha = tempAlpha;
m_alphaSize = strlen(m_alpha);
//check alpha stream for nonsense or spaces
//if nonsense, output error, if space, remove space
for(int k = 0; k < m_alphaSize; k++)
{
if(!(isalnum(m_alpha[k])))
{
cerr << "Alphabet contains characters which are not alphanumeric: "
<< m_alpha[k] << "\n";
exit(1);
}
}
}
//////////////////////////////////////////////////////////////////////////
// Function: ParseTree::CheckDataInput
// Purpose: checks the data string for spaces or nonsense
// In Params: ParseTree class variables --- m_data, m_dataSize, m_alphaSize
// Out Params: none
// In/Out Params: none
// Pre- Cond: Alpha and Data files have been read in
// Post-Cond: Alphabet and Data info in ParseTree class is valid
//////////////////////////////////////////////////////////////////////////
void ParseTree::CheckDataInput()
{
bool accept_flag = false;
char* tempData = new char[m_dataSize];
char seps[] = " ,\t\n\r";
char* token;
//first, remove white spaces, tabs, or endlines
token = strtok(m_data, seps );
strcpy(tempData,token);
while( token != NULL )
{
/* Get next token: */
token = strtok( NULL, seps );
if(token!=NULL)
strcat(tempData,token);
}
//make necessary adjustments to data and size
delete[] m_data;
m_data = tempData;
m_dataSize = strlen(m_data);
//check data stream for characters which
//are not in the designated alphabet
for(int i = 0; i < m_dataSize; i++)
{
for(int j = 0; j < m_alphaSize; j++)
{
if(m_data[i] == m_alpha[j])
accept_flag = true;
}
if(accept_flag)
accept_flag = false;
//if symbol is not in alphabet, check for spaces
else
{
cerr << "Data contains characters which are not in the alphabet: "
<< m_data[i] <<"\n";
exit(1);
}
}
}
//////////////////////////////////////////////////////////////////////////
// Function: ParseTree::ReadInput
// Purpose: reads in the alphabet of symbols and data string
// In Params: the input filenames
// Out Params: an integer that denotes failure or success
// In/Out Params: none
// Pre- Cond: Filenames must have been read in at command line,
// size of alphabet file must be smaller than data file
// Post-Cond: Alphabet,Data arrays and related info in ParseTree class set
//////////////////////////////////////////////////////////////////////////
void ParseTree::ReadInput(char alphaFile[], char dataFile[])
{
//Read in files
GetDataInput(dataFile);
GetAlphaInput(alphaFile);
//Remove any extra spaces, endlines, etc.
//And make sure input is valid
CheckAlphaInput();
CheckDataInput();
return;
}
///////////////////////////////////////////////////////////////////////////
// Function: ParseTree::DecStringCount
// Purpose: decrements the recorded occurence of a string in the Parse Tree
// In Params: the string to decrement and the root of the current subtree
// Out Params: none
// In/Out Params: none
// Pre- Cond: none
// Post-Cond: counts of the string in the tree are one lower at each symbol
//////////////////////////////////////////////////////////////////////////
void ParseTree::DecStringCount(char string[], TreeNode*& root)
{
//base case, we are done with string
if(strlen(string) < 1)
return;
//a node does not exist for this substring
if(root == NULL)
{
//no match
cerr << "Attempting to decrement occurence of string which doesn't "
<< "show up in data, ParseTree::DecStringCount " << endl;
exit(1);
}
//this substring already exists
else if(root->m_symbol==string[0])
{
//increase the count of the substring
root->m_count--;
//and make recursive call
DecStringCount(&(string[1]), root->m_child);
}
//the substring may be in a sibling node
else if(root->m_symbol!=string[0])
{
TreeNode** temp;
temp = &root;
while(*temp!=NULL && (*temp)->m_symbol!= string[0])
temp = &((*temp)->m_sibling);
//or if not, it should be added there
if(*temp == NULL)
{
//no match
cerr << "Attempting to decrement occurence of string which doesn't "
<< "show up in data, ParseTree::DecStringCount " << endl;
exit(1);
}
(*temp)->m_count--;
//recursive call made with sibling node
DecStringCount(&(string[1]), (*temp)->m_child);
}
}
///////////////////////////////////////////////////////////////////////////
// Function: ParseTree::MakeSynchAdjustments
// Purpose: decrements the recorded occurence of synchronization data
// in the Parse Tree
// In Params: the synchronization string and the index at which synchronization
// ended
// Out Params: none
// In/Out Params: none
// Pre- Cond: tree exits, counts are positive
// Post-Cond: tree counts have been adjusted for all max lenght substrings
// of the synch data
//////////////////////////////////////////////////////////////////////////
void ParseTree::MakeSynchAdjustements(char* synchString, int index)
{
int counter = 0;
int stringLength = strlen(synchString);
char* tempString = new char[stringLength + m_maxLength + END_STRING];
char* nextLString = new char[m_maxLength + END_STRING];
strcpy(tempString, synchString);
int i,j,k;
int tempCounter = 0;
for(i = 0; i < m_maxLength - 1; i++)
nextLString[i] = m_data[index - 1 + i];
nextLString[i] = '\0';
strcat(tempString, nextLString);
//look at all max length strings and decrement occurences
if(strlen(tempString) >= m_maxLength)
{
while(counter < (strlen(tempString) - m_maxLength))
{
for(k= 0; k < m_maxLength; k++)
nextLString[k] = tempString[k+ counter];
counter++;
nextLString[k] = '\0';
DecStringCount(nextLString);
}
}
for(k=0; k < m_maxLength;k++)
{
for(j =0; j <m_maxLength-k;j++)
nextLString[j] = tempString[k + j];
nextLString[j] = '\0';
DecStringCount(nextLString);
}
m_adjustedDataSize -=(strlen(synchString) - (m_maxLength - 1));
}
//////////////////////////////////////////////////////////////////////////
// Function: ParseTree::Read_Process_MultiLine
// Purpose: reads in the alphabet of symbols and data strings and fills tree
// In Params: the input files
// Out Params: an integer that denotes failure or success
// In/Out Params: none
// Pre- Cond: Filenames must have been read in at command line,
// size of alphabet file must be smaller than data file
// Post-Cond: Alphabet and Data arrays are set, and tree is filled
//////////////////////////////////////////////////////////////////////////
void ParseTree::ReadProcessMultiLine(char alphaFile[], char dataFile[])
{
int size = 0;
int total_size = 0;
char* buffer = new char[MAX_LINE_SIZE + END_STRING];
int offset = 1;
bool accept_flag = false;
//create file streams
ifstream inData(dataFile, ios::in);
ifstream inAlpha(alphaFile, ios::in);
//open alphabet file, if unsuccessful set boolean return value
if(!inAlpha.is_open())
{
cerr << " the alphabet file cannot be opened " << endl;
exit(1);
}
//otherwise read in data until end of file
else
{
inAlpha.seekg(0,ios::end);
size = inAlpha.tellg();
inAlpha.seekg(0,ios::beg);
m_alpha = new char[size + 1];
inAlpha.get(m_alpha,size + 1,'\0');
if(m_alpha[size - 2] == '\n')
offset = 2;
else if(m_alpha[size - 1] == '\n')
offset =1;
else if(isalnum(m_data[size - 1]))
offset = 0;
m_alpha[size - offset] = '\0';
inAlpha.close();
m_alphaSize = strlen(m_alpha);
}
//open data file, if unsuccessful set boolean return value
if(!inData.is_open())
{
cerr << " the data file cannot be opened " << endl;
exit(1);
}
//otherwise read in data until end of line, then
//fill tree with each line
else
{
inData.seekg(0,ios::end);
size = inData.tellg();
inData.seekg(0,ios::beg);
m_data = new char[size + SYSTEM_CONST];
inData.getline(buffer, MAX_LINE_SIZE);
total_size = size;
size = 0;
m_numLines++;
strcpy(m_data,buffer);
m_dataSize = strlen(m_data);
FillTree();
size+=m_dataSize;
while (!inData.eof())
{
inData.getline(buffer, MAX_LINE_SIZE);
m_numLines++;
strcpy(m_data,buffer);
m_dataSize = strlen(m_data);
FillTree();
size+=m_dataSize;
}
m_dataSize = size;
m_adjustedDataSize = m_numLines *(m_dataSize - (m_maxLength - 1));
//read in full data stream, to record all data
inData.clear();
inData.seekg(0,ios::beg);
inData.get(m_data,total_size,'\0');
inData.close();
//check alphabet
for(int k = 0; k < m_alphaSize; k++)
{
if(!(isalnum(m_alpha[k])))
{
cerr << "Alphabet contains characters which are not"
<< " alphanumeric.\n";
exit(1);
}
}
//check data stream
for(int i = 0; i < m_dataSize; i++)
{
for(int j = 0; j < m_alphaSize; j++)
{
if(m_data[i] == m_alpha[j] || m_data[i] == '\n')
accept_flag = true;
}
if(accept_flag)
accept_flag = false;
else
{
cerr << "Data contains characters which are not in the"
<< " alphabet.\n";
exit(1);
}
}
}
return;
}
///////////////////////////////////////////////////////////////////////////
// Function: ParseTree::FindRoots
// Purpose: collects all strings of length 1 in an array, and their
// unconditional frequencies in another array
// In Params: root of the tree
// Out Params: the size of the arrays, the arrays of symbols and frequencies
// In/Out Params: none
// Pre- Cond: tree exists
// Post-Cond: strings of length 1 have been put in an array
// and their frequencies have been put in another
//////////////////////////////////////////////////////////////////////////
int ParseTree::FindRoots(TreeNode* root, char charArray[], int intArray[])
{
int size = 0;
//check to make sure data exists
if(m_dataSize == 0)
{
cerr << "no data in tree" << endl;
exit(1);
}
while(root != NULL)
{
charArray[size] = root->m_symbol;
intArray[size] = root->m_count;
size++;
root = root->m_sibling;
}
return size;
}