Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
List add v2
//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; } }; int node_to_num(node *n) { int num = n->num; node *cur = n->next; while (cur) { num = (num * 10) + cur->num; cur = cur->next; } return (int)num; } node* num_to_node(int num) { node *n = NULL; while (num > 0) { n = new node(num % 10, n); num /= 10; } return n; } node* node_add(node* n1, node* n2) { int num1 = node_to_num(n1); int num2 = node_to_num(n2); return num_to_node(num1 + num2); } // [1] -> [2] -> [3] -> [4] -> [] // [] <- [1] <- [2] <- [3] <- [4] node* reverse(node* n) { node *perv = NULL; node *cur = n; node *next = n->next; if (next) while (cur) { cur->next = perv; perv = cur; if (next) { cur = next; next = cur->next; } else { break; } } return cur; } void print(node* n) { while(n) { cout << n->num << " "; n = n->next; } cout << endl; } int main() { node *n1 = new node(1, new node(2, new node(3, NULL))); node *n2 = new node(2, new node(3, new node(4, NULL))); n1 = reverse(n1); print(n1); print(n2); node *n = node_add(n1, n2); cout << node_to_num(n); }
run
|
edit
|
history
|
help
0
Problema2
const test
cp.cpp
BadCastAllExcept
gp series
Rrrrrrrr
რიცხვები დაფაზა~ფინალური
Speed
CPP - ex 5 - solution
Making pyramid using nested loop 1/2