Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
List add
//Title of this code #include <iostream> using namespace std; struct node { int num; node* next; node(int num, node* next) { this->num = num; this->next = next; } }; inline int pow_of_ten(int x) { int r = 1; for (int i = 0; i < x; ++i) r *= 10; return r; } int node_to_num(node *n) { const int max_num = 8; int num = 0; int i = max_num; node *cur = n; while (cur) { num += cur->num * pow_of_ten(i--); cur = cur->next; } num /= pow_of_ten(i + 1); return num; } node* node_add(node* n1, node* n2) { int num1 = node_to_num(n1); int num2 = node_to_num(n2); num1 += num2; node *n = NULL; while (num1 > 0) { n = new node(num1 % 10, n); num1 /= 10; } return n; } int main() { node *n1 = new node(9, new node(8, new node(7, NULL))); node *n2 = new node(2, new node(3, new node(4, NULL))); node *n = node_add(n1, n2); cout << node_to_num(n); }
run
|
edit
|
history
|
help
0
New wall
Making pyramid using nested loop 1/2
template
typecasting
simple use of templete
find duplicate in O(n)
DailyExchRate2
HeatPump COP
Game
Eratosfen conmment