Given a linked list of six nodes (i.e. the first node is pointed by head, the la
ID: 3837027 • Letter: G
Question
Given a linked list of six nodes (i.e. the first node is pointed by head, the last node's next is NULL). Adjust the list by calling list_adjust() function to switch the 3^rd node and the 4^th node (i.e. make the 2^nd node's next point to the 4^th node, the 4^th node's next point to the 3^rd node, and the 3^rd node's next point to the 5^th node. #include Using namespace std; struct ex {int value; node * next;}; void list_adjust({//Complete the code} int main() {node * head, * temp; list_adjust();}Explanation / Answer
This method does not require a loop
void list_adjust(struct ex *head){
struct ex * first = head ;
struct ex * second = head->next ;
struct ex * third = second->next ;
struct ex * fourth = third->next ;
struct ex * fifth = fourth->next;
second->next = fourth;
fourth->next = third;
third->next = fifth;
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.