EC Lecture Notes - Lecture 1: Linked List

7 views3 pages

Document Summary

L: l0 l1 ln-1 ln, reorder it to: You must do this in-place without altering the nodes" values. Given {1,2,3,4} , reorder it to {1,4,2,3} . // c++ program to rearrange a linked list in-place. // linkedlist node structure struct node { int data; struct node* next; // function to create newnode in a linkedlist. Node* temp = new node; temp->data = key; temp->next = null; return temp; // function to reverse the linked list void reverselist(node** head) Node *prev = null, *curr = *head, *next; while (curr) { next = curr->next; curr->next = prev; prev = curr; curr = next; *head = prev; reorder list1// function to print the linked list void printlist(node* head) while (head != null) { cout << head->data << " "; if (head->next) cout << "-> "; head = head->next; cout << endl; // function to rearrange a linked list void rearrange(node** head) // 1) find the middle point using tortoise and hare.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents