Course Hero Logo

Ex 25 42 12 check next 310 linked list traversal

Course Hero uses AI to attempt to automatically extract content from documents to surface to you and others so you can study better, e.g., in search results, to enrich docs, and more. This preview shows page 16 - 18 out of 37 pages.

Ex: 25, 42, 12CheckNext3.10 Linked list traversalLinked list traversalAlist traversalalgorithm visits all nodes in the list once and performs an operation on each node. Acommon traversal operation prints all list nodes. The algorithm starts by pointing a curNode pointer tothe list's head node. While curNode is not null, the algorithm prints the current node, and then pointscurNode to the next node. After the list's tail node is visited, curNode is pointed to the tail node's nextnode, which does not exist. So, curNode is null, and the traversal ends. The traversal algorithmsupports both singly-linked and doubly-linked lists.Figure 3.10.1: Linked list traversal algorithm.ListTraverse(list) {curNode = listhead // Start atheadwhile (curNode is not null) {Print curNode's datacurNode = curNodenext}}PARTICIPATIONACTIVITY3.10.1: Singly-linked list: List traversal.1©zyBooks 10/04/22 16:42 1446384Valeria Taglioni ChicaWUSTLCSE247502NFall2022©zyBooks 10/04/22 16:42 1446384Valeria Taglioni ChicaWUSTLCSE247502NFall2022PARTICIPATIONACTIVITY3.10.2: List traversal.1)ListTraverse begins with _____.2)Given numsList is: 5, 8, 2, 1.ListTraverse(numsList) visits _____node(s).3)ListTraverse can be used to traverse adoubly-linked list.Doubly-linked list reverse traversalA doubly-linked list also supports a reverse traversal. Areverse traversalvisits all nodes starting withthe list's tail node and ending after visiting the list's head node.Figure 3.10.2: Reverse traversal algorithm.Animation content:undefinedAnimation captions:1. Traverse starts at the list's head node.2. curNode's data is printed, and then curNode is pointed to the next node.3. After the list's tail node is printed, curNode is pointed to the tail node's next node, which doesnot exist.4. The traversal ends when curNode is null.a speci±ed list nodethe list's head nodethe list's tail nodeonetwofourTrueFalse©zyBooks 10/04/22 16:42 1446384Valeria Taglioni ChicaWUSTLCSE247502NFall2022©zyBooks 10/04/22 16:42 1446384Valeria Taglioni ChicaWUSTLCSE247502NFall2022
ListTraverseReverse(list) {curNode = listtail // Start attailwhile (curNode is not null) {Print curNode's datacurNode = curNodeprev}}PARTICIPATIONACTIVITY3.10.3: Reverse traversal algorithm execution.1)ListTraverseReverse visits which nodesecond?2)ListTraverseReverse can be used totraverse a singly-linked list.Node 2Node 13TrueFalse3.11 Sorting linked listsInsertion sort for doubly-linked listsInsertion sort for a doubly-linked list operates similarly to the insertion sort algorithm used for arrays.Starting with the second list element, each element in the linked list is visited. Each visited element is©zyBooks 10/04/22 16:42 1446384Valeria Taglioni ChicaWUSTLCSE247502NFall2022©zyBooks 10/04/22 16:42 1446384Valeria Taglioni ChicaWUSTLCSE247502NFall2022moved back as needed and inserted into the correct position in the list's sorted portion. The list mustbe a doubly-linked list, since backward traversal is not possible in a singly-linked list.

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 37 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
Goldman
Tags
List Abstract Data Type, List node data structure

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture