Professional Documents
Culture Documents
#include <bits/stdc++.h>
struct Node
int data;
};
/* allocate node */
new_node->data = new_data;
new_node->next = *head_ref;
*head_ref = new_node;
}
slow = head;
fast = head->next;
fast = fast->next;
if (fast != NULL)
slow = slow->next;
fast = fast->next;
*front_ref = head;
*back_ref = slow->next;
slow->next = NULL;
current = *head_ref;
prev = NULL;
next = current->next;
current->next = prev;
prev = current;
current = next;
*head_ref = prev;
// modification
back = back->next;
// the 1st(front) list and returns the head of the new list
front = front->next;
front->next = back;
return head;
return head;
reverseList(&back);
modifyTheContentsOf1stHalf(front, back);
reverseList(&back);
return head;
if (!head)
return;
head = head->next;
int main()
push(&head, 10);
push(&head, 7);
push(&head, 12);
push(&head, 8);
push(&head, 9);
push(&head, 2);
head = modifyTheList(head);
printList(head);
return 0;
}
void reverse(){
cur = *head;
prev = NULL;
newptr = cur->newptr;
current->newptr = prev;
prev = cur;
cur = newptr;
*head = prev;