2020 */
2121void radix (std::vector<int > &v) {
2222 // the number of digits of max element indicates how many times the main loop will be executed
23- int max_d = std::to_string (*std::max_element (v.begin (), v.end ())).size ();
23+ int maxDig = std::to_string (*std::max_element (v.begin (), v.end ())).size ();
2424
2525 // one bucket for each digit from 0 to 9
2626 std::array<std::vector<int >, 10 > buckets;
2727
28- // main loop; max_d times
29- for (int i = 0 ; i < max_d ; i++) {
28+ // main loop; maxDig times
29+ for (int i = 0 ; i < maxDig ; i++) {
3030 // inter loop; insert each element into its respective bucket depending on which digit position is being analyzed
3131 std::for_each (v.begin (), v.end (), [&buckets, i](int value){ buckets[(int )(value/std::pow (10 , i))%10 ].push_back (value); });
3232
@@ -52,7 +52,7 @@ void radix(std::vector<int> &v) {
5252/* !
5353 * Simple print function.
5454 */
55- void print_v (std::vector<int > v) {
55+ void printV (std::vector<int > v) {
5656 for (int i = 0 ; i < v.size (); i++) std::cout << v[i] << " " ;
5757 std::cout << std::endl;
5858}
@@ -61,12 +61,12 @@ void print_v(std::vector<int> v) {
6161 * This function separates the main vector into two: one containing negative integers and one containing non-negative integers.
6262 *
6363 * @param v Vector with non-negative integers.
64- * @param neg_v Vector with negative integers.
64+ * @param negV Vector with negative integers.
6565 */
66- void split_v (std::vector<int > &v, std::vector<int > &neg_v ) {
66+ void splitV (std::vector<int > &v, std::vector<int > &negV ) {
6767 for (int i = 0 ; i < v.size (); i++) {
6868 if (v[i] < 0 ) {
69- neg_v .push_back (v[i]);
69+ negV .push_back (v[i]);
7070 v.erase (v.begin () + i);
7171 }
7272 }
@@ -77,42 +77,42 @@ void split_v(std::vector<int> &v, std::vector<int> &neg_v) {
7777 *
7878 * @param v Vector whose elements will be changed.
7979 */
80- void neg_pos (std::vector<int > &v) {
80+ void negPos (std::vector<int > &v) {
8181 for (auto &a : v) {
8282 a *= -1 ;
8383 }
8484}
8585
8686/* !
87- * This function joins two vectors.
87+ * This function joinVs two vectors.
8888 *
8989 * @param v Vector with non-negative integers.
90- * @param neg_v Vector with negative integers.
90+ * @param negV Vector with negative integers.
9191 */
92- void join (std::vector<int > &v, std::vector<int > &neg_v ) {
92+ void joinV (std::vector<int > &v, std::vector<int > &negV ) {
9393 // reverses because the original values are negative
94- std::reverse (neg_v .begin (), neg_v .end ());
95- for (auto &a : neg_v ) v.insert (v.begin (), a);
94+ std::reverse (negV .begin (), negV .end ());
95+ for (auto &a : negV ) v.insert (v.begin (), a);
9696}
9797
9898
9999int main () {
100100 std::vector<int > v = {23 , -10 , 20 , -11 , 12 , -6 , 7 };
101- std::vector<int > neg_v ;
101+ std::vector<int > negV ;
102102
103- split_v (v, neg_v );
103+ splitV (v, negV );
104104
105- neg_pos (neg_v );
105+ negPos (negV );
106106
107107 radix (v);
108- radix (neg_v );
108+ radix (negV );
109109
110- neg_pos (neg_v );
110+ negPos (negV );
111111
112- join (v, neg_v );
112+ joinV (v, negV );
113113
114114 std::cout << " Sorted: " ;
115- print_v (v);
115+ printV (v);
116116
117117 return 0 ;
118- }
118+ }
0 commit comments