mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
more cpp lint fixes
This commit is contained in:
parent
e989ad0fe5
commit
045a1dc977
@ -3,8 +3,8 @@
|
|||||||
* @email krishna (dot) vedala (at) ieee (dot) org
|
* @email krishna (dot) vedala (at) ieee (dot) org
|
||||||
**/
|
**/
|
||||||
|
|
||||||
#ifndef __LARGE_NUMBER__
|
#ifndef OTHERS_LARGE_NUMBER_H_
|
||||||
#define __LARGE_NUMBER__
|
#define OTHERS_LARGE_NUMBER_H_
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -19,10 +19,7 @@
|
|||||||
**/
|
**/
|
||||||
class large_number {
|
class large_number {
|
||||||
public:
|
public:
|
||||||
large_number() /**< initializer with value = 1 */
|
large_number() /**< initializer with value = 1 */ { _digits.push_back(1); }
|
||||||
{
|
|
||||||
_digits.push_back(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
large_number(unsigned long n) /**< initializer from an integer */
|
large_number(unsigned long n) /**< initializer from an integer */
|
||||||
{
|
{
|
||||||
@ -49,7 +46,8 @@ class large_number {
|
|||||||
{
|
{
|
||||||
for (size_t i = strlen(number_str); i > 0; i--) {
|
for (size_t i = strlen(number_str); i > 0; i--) {
|
||||||
unsigned char a = number_str[i - 1] - '0';
|
unsigned char a = number_str[i - 1] - '0';
|
||||||
if (a >= 0 && a <= 9) _digits.push_back(a);
|
if (a >= 0 && a <= 9)
|
||||||
|
_digits.push_back(a);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,9 +146,11 @@ class large_number {
|
|||||||
**/
|
**/
|
||||||
friend bool operator==(large_number const &a, large_number const &b) {
|
friend bool operator==(large_number const &a, large_number const &b) {
|
||||||
size_t N = a.num_digits();
|
size_t N = a.num_digits();
|
||||||
if (N != b.num_digits()) return false;
|
if (N != b.num_digits())
|
||||||
|
return false;
|
||||||
for (size_t i = 0; i < N; i++)
|
for (size_t i = 0; i < N; i++)
|
||||||
if (a[i] != b[i]) return false;
|
if (a[i] != b[i])
|
||||||
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,8 +191,10 @@ class large_number {
|
|||||||
unsigned int carry = 0;
|
unsigned int carry = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0; i < max_L || carry != 0; i++) {
|
for (i = 0; i < max_L || carry != 0; i++) {
|
||||||
if (i < b->num_digits()) carry += (*b)[i];
|
if (i < b->num_digits())
|
||||||
if (i < this->num_digits()) carry += (*this)[i];
|
carry += (*b)[i];
|
||||||
|
if (i < this->num_digits())
|
||||||
|
carry += (*this)[i];
|
||||||
if (i < this->num_digits())
|
if (i < this->num_digits())
|
||||||
(*this)[i] = carry % 10;
|
(*this)[i] = carry % 10;
|
||||||
else
|
else
|
||||||
@ -275,4 +277,4 @@ class large_number {
|
|||||||
_digits; /**< where individual digits are stored */
|
_digits; /**< where individual digits are stored */
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif // OTHERS_LARGE_NUMBER_H_
|
||||||
|
Loading…
Reference in New Issue
Block a user