1 / 9

Inverting a Singly Linked List

Inverting a Singly Linked List. Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals of Data Structures in C “. . Inverting a Singly Linked List. NULL. middle = NULL;. while (lead) {. trail = middle;. middle = lead;.

esteban
Download Presentation

Inverting a Singly Linked List

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Inverting a Singly Linked List Instructor : Prof. Jyh-Shing Roger Jang Designer:Shao-Huan Wang The ideas are reference to the textbook “Fundamentals of Data Structures in C “.

  2. Inverting a Singly Linked List NULL middle = NULL; while (lead) { trail = middle; middle = lead; lead = lead->link; middle->link = trail; } return middle;

  3. Inverting a Singly Linked List ↓trail NULL NULL ↑middle First, initial the middle = NULL middle = NULL; while (lead) { trail = middle; middle = lead; lead = lead->link; middle->link = trail; } return middle;

  4. Inverting a Singly Linked List ↓trail NULL NULL ↑middle First, initial the middle = NULL middle = NULL; while (lead) { And continue loop until lead == NULL trail = middle; middle = lead; lead = lead->link; middle->link = trail; } return middle;

  5. Inverting a Singly Linked List ↓trail NULL NULL ↑middle First, initial the middle = NULL middle = NULL; while (lead) { And continue loop until lead == NULL trail = middle; middle = lead; lead = lead->link; middle->link = trail; } return middle;

  6. Inverting a Singly Linked List ↓trail NULL NULL ↑middle First, initial the middle = NULL middle = NULL; while (lead) { And continue loop until lead == NULL trail = middle; middle = lead; lead = lead->link; middle->link = trail; } return middle;

  7. Inverting a Singly Linked List ↓trail NULL NULL ↑middle First, initial the middle = NULL middle = NULL; while (lead) { And continue loop until lead == NULL trail = middle; middle = lead; lead = lead->link; middle->link = trail; } return middle;

  8. Inverting a Singly Linked List ↓trail NULL NULL ↑middle First, initial the middle = NULL middle = NULL; while (lead) { And continue loop until lead == NULL trail = middle; lead == NULL, break the loop middle = lead; lead = lead->link; middle->link = trail; } return middle;

  9. Inverting a Singly Linked List ↓trail NULL NULL ↑middle First, initial the middle = NULL middle = NULL; while (lead) { And continue loop until lead == NULL trail = middle; lead == NULL, break the loop middle = lead; return middle as the lead of linked list lead = lead->link; middle->link = trail; } return middle;

More Related