File tree 19 files changed +117367
-0
lines changed
19 files changed +117367
-0
lines changed Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 3.8)
2
+ project (1_FrequencyCounter)
3
+
4
+ set (CMAKE_CXX_STANDARD 14)
5
+
6
+ set (SOURCE_FILES main.cpp ../head/ST.h ../head/SequentialSearchST.h ../head/BinarySearchST.h ../head/BST.h)
7
+ add_executable (1_FrequencyCounter ${SOURCE_FILES} )
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < fstream>
3
+ #include " ../head/ST.h"
4
+
5
+ using namespace std ;
6
+
7
+ int main () {
8
+ int distinct = 0 , words = 0 ;
9
+ int minlen = 8 ;
10
+ ST<string, int > st;
11
+ fstream file (" /home/ace/AceDev/C++/algorithm/ch3/data/tale.txt" );
12
+ string key;
13
+ // compute frequency counts
14
+ while (file >> key) {
15
+ if (key.length () < minlen)
16
+ continue ;
17
+ words++;
18
+ if (st.contains (key))
19
+ st.put (key, st.get (key) + 1 );
20
+ else {
21
+ st.put (key, 1 );
22
+ distinct++;
23
+ }
24
+ }
25
+ string max;
26
+ int vmax = 0 ;
27
+ // find a key with the highest frequency count
28
+ for (auto s: st) {
29
+ if (s.second > vmax) {
30
+ max = s.first ;
31
+ vmax = s.second ;
32
+ }
33
+ }
34
+ cout << max << " " << vmax << " times" << endl;
35
+ cout << " distinct = " << distinct << endl;
36
+ cout << " words = " << words << endl;
37
+
38
+ }
Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 3.8)
2
+ project (2_SequentialSearchST)
3
+
4
+ set (CMAKE_CXX_STANDARD 14)
5
+
6
+ set (SOURCE_FILES main.cpp ../head/ST.h ../head/SequentialSearchST.h)
7
+ add_executable (2_SequentialSearchST ${SOURCE_FILES} )
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < fstream>
3
+ #include " ../head/SequentialSearchST.h"
4
+
5
+ using namespace std ;
6
+
7
+ int main () {
8
+ SequentialSearchST<string, int > st;
9
+ fstream file (" /home/ace/AceDev/C++/algorithm/ch3/data/tinyST.txt" );
10
+ string key;
11
+ int cnt = 0 ;
12
+ // compute frequency counts
13
+ while (file >> key) {
14
+ st.put (key, cnt);
15
+ cnt++;
16
+ }
17
+
18
+ for (auto s: st) {
19
+ cout << s << " " << st.get (s) << endl;
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 3.8)
2
+ project (3_BinarySearchST)
3
+
4
+ set (CMAKE_CXX_STANDARD 14)
5
+
6
+ set (SOURCE_FILES main.cpp ../head/ST.h ../head/SequentialSearchST.h)
7
+ add_executable (3_BinarySearchST ${SOURCE_FILES} )
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < fstream>
3
+ #include " ../head/BinarySearchST.h"
4
+
5
+ using namespace std ;
6
+
7
+ int main () {
8
+ BinarySearchST<string, int > st;
9
+ fstream file (" /home/ace/AceDev/C++/algorithm/ch3/data/tinyST.txt" );
10
+ string key;
11
+ int cnt = 0 ;
12
+ // compute frequency counts
13
+ while (file >> key) {
14
+ st.put (key, cnt);
15
+ cnt++;
16
+ }
17
+
18
+ for (auto s: st) {
19
+ cout << s << " " << st.get (s) << endl;
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 3.8)
2
+ project (4_BST)
3
+
4
+ set (CMAKE_CXX_STANDARD 14)
5
+
6
+ set (SOURCE_FILES main.cpp ../head/ST.h ../head/SequentialSearchST.h)
7
+ add_executable (4_BST ${SOURCE_FILES} )
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < fstream>
3
+ #include " ../head/BST.h"
4
+
5
+ using namespace std ;
6
+
7
+ int main () {
8
+ BST<string, int > st;
9
+ fstream file (" /home/ace/AceDev/C++/algorithm/ch3/data/tinyST.txt" );
10
+ string key;
11
+ int cnt = 0 ;
12
+ // compute frequency counts
13
+ while (file >> key) {
14
+ st.put (key, cnt);
15
+ cnt++;
16
+ }
17
+
18
+ vector<string> mid = st.midOrder ();
19
+ for (auto a: mid)
20
+ cout << a << " " << st.get (a) << endl;
21
+ cout << " ----------level order-----------" << endl;
22
+ vector<string> level = st.levelOrder ();
23
+ for (auto a:level)
24
+ cout << a << " " << st.get (a) << endl;
25
+
26
+ }
Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 3.8)
2
+ project (8_ST)
3
+
4
+ set (CMAKE_CXX_STANDARD 14)
5
+
6
+ set (SOURCE_FILES main.cpp ../head/ST.h)
7
+ add_executable (8_ST ${SOURCE_FILES} )
Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < fstream>
3
+ #include " ../head/ST.h"
4
+
5
+ using namespace std ;
6
+
7
+ int main () {
8
+ ST<string, int > st;
9
+ fstream file (" /home/ace/AceDev/C++/algorithm/ch3/data/tinyST.txt" );
10
+ string tmp;
11
+ int cnt = 0 ;
12
+ while (file >> tmp) {
13
+ st.put (tmp, cnt++);
14
+ }
15
+ for (auto s: st)
16
+ cout << s.first << " " << s.second << endl;
17
+ }
Original file line number Diff line number Diff line change
1
+ cmake_minimum_required (VERSION 3.8)
2
+ project (ch3)
3
+
4
+ set (CMAKE_CXX_STANDARD 14)
5
+
6
+ include_directories (head)
7
+
8
+ add_subdirectory (1_FrequencyCounter)
9
+ add_subdirectory (2_SequentialSearchST)
10
+ add_subdirectory (3_BinarySearchST)
11
+ add_subdirectory (4_BST)
12
+
13
+ add_subdirectory (8_ST)
You can’t perform that action at this time.
0 commit comments