Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Bad Code2
//Title of this code #include <iostream> using namespace std; struct Node { Node *next; int e; Node(Node *p, int n): next(p), e(n) {} }; /* void rev(Node *first, int k) { Node *cur, *tmp, *tmp2, *tmp3; cur = first; while (cur != NULL) { int i = k; tmp = cur; while (i > 0) { tmp2 = cur; cur = cur->next; if (!cur) break; --i; tmp3 = cur; cur->next = tmp2; cur = tmp3; } if (i == 0) { } } } */ Node* rev(Node* first) { if (!first->next) return first; Node *cur_perv, *cur_next, *cur; cur_perv = first; cur = first->next; first->next = NULL; while ( cur != NULL ) { if (cur->next != NULL) { cur_next = cur->next; cur->next = cur_perv; cur_perv = cur; cur = cur_next; } else break; } cur->next = cur_perv; return cur; } void print(Node *first) { while (first != NULL) { cout << first->e << " "; first = first->next; } cout << endl; } int main() { //Node *first = new Node(new Node(new Node(new Node(new Node(new Node(new Node(NULL, 7), 6), 5), 4), 3), 2), 1); //Node *first = new Node(new Node(new Node(NULL, 3), 2), 1); Node *first = new Node(new Node(NULL, 2), 1); //rev(first, 3); first = rev(first); print(first); cout << "Hello, world!\n"; }
run
|
edit
|
history
|
help
0
Simulare 2022 SIII, 1
sdfg
virtual function
Radix
Best way for getting more precision no.
Using copy_n
Wipro Problem 2: determine count
Próba
integer division
PriQTel2