Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
delete from list
//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); }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
throwing std::function on MSVC is dangerous
msvc compile optimization demo...
😊
Compile time creation of class member stl container (const std::array) filled with elements.
success
Type deduction in VC++
post_decrement_example
operator new / delete
algorithm_1
vector destruction - visual studio
Please log in to post a comment.