Run Code
|
API
|
Code Wall
|
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
Zero length array as a class member
#31
Hangman
Hangman
RVO hota hai bhenchod
Spirit Lex combining token_id's with semantic actions
not a parameter pack
sharedptr emptiness
zero size std::array parameter
Two-phase sample with Visual C++ 2015