Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Bad Code2
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//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"; }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.65 sec, absolute running time: 0.07 sec, cpu time: 0 sec, memory peak: 3 Mb, absolute service time: 0.73 sec
edit mode
|
history
|
discussion
2 1 Hello, world!