Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
delete from list
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 { int data; node* next; node(int d, node* n): data(d), next(n) {} }; node* alterList(node* head, int n, int m) { node* cur = head; node* prev = NULL; node* first = head; while (cur) { int i = n; int j = m; while (cur && i > 0) { prev = cur; cur = cur->next; first = cur; --i; } if (!cur) break; while (cur && j > 0) { node* tmp = cur; cur = cur->next; delete tmp; --j; } if (prev) prev->next = cur; } if (first == head) return NULL; return head; } void print(node* head) { while (head) { cout << head->data << " "; head = head->next; } cout << endl; } int main() { node* head = new node(1, new node(2, new node(3, new node(4, new node(5, new node(6, new node(7, new node(8, new node(9, NULL))))))))); print(head); head = alterList(head, 0, 2); print(head); }
cl.exe
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 1.14 sec, absolute running time: 0.06 sec, absolute service time: 1.2 sec
fork mode
|
history
|
discussion
1 2 3 4 5 6 7 8 9