TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Separates digits from numbers in forward and reverse order. More...
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <vector>
Go to the source code of this file.
Classes | |
class | greedy_algorithms::DigitSeparation |
A class that provides methods to separate the digits of a large positive number. More... | |
Namespaces | |
namespace | greedy_algorithms |
for string class | |
Functions | |
static void | tests () |
self test implementation | |
int | main () |
main function | |
Separates digits from numbers in forward and reverse order.
The DigitSeparation class provides two methods to separate the digits of large integers: digitSeparationReverseOrder and digitSeparationForwardOrder. The digitSeparationReverseOrder method extracts digits by repeatedly applying the modulus operation (% 10) to isolate the last digit, then divides the number by 10 to remove it. This process continues until the entire number is broken down into its digits, which are stored in reverse order. If the number is zero, the method directly returns a vector containing {0} to handle this edge case. Negative numbers are handled by taking the absolute value, ensuring consistent behavior regardless of the sign.
Definition in file digit_separation.cpp.
int main | ( | void | ) |
main function
Definition at line 138 of file digit_separation.cpp.
|
static |
self test implementation
Definition at line 83 of file digit_separation.cpp.