Implement the algorithms in C++ program. Algorithm 1: (Traversing a Linked List) Let LIST be a linked list in memory. This algorithm traverses LIST, applying an operation PROCESS to each Node/element of the LIST. HEAD points to the first node of the LIST. Pointer variable CURR points to the node currently being processed. Step 1. Set CURR = HEAD. [Initializes pointer CURR.] Step 2. Repeat Steps 3 and 4 while CURR ≠ NULL. Step 3. Apply PROCESS to CURR -> INFO. Step 4. Set CURR = CURR -> NEXT [CURR now points to the next node.] [End of Step-2 loop.] Step 5. End   Algorithm2: INSERT( ITEM) NOTE: Here it is needed that all the time, LIST should remains in the sorted order using Info part of the Node. To Insert / Enqueue a new node in the LIST, first LIST will be searched (using Info of Nodes) to find its LOCATION ( where to insert new Node). This exercise makes it possible that every new node has the probability to insert at the beginning, in the middle or at the end of LIST. CURR is a pointer points to the node currently being processed and PREV is a pointer pointing to previous node of the current node. [This algorithm adds NewNodes at any position (Top, in Middle OR at End) in the List ] Step 1. Create NewNode node for LIST in memory Step 2. Set NewNode -> Info =ITEM. [Copies new data into INFO of new node.] Step 3. NewNode -> Next = NULL. [Copies NULL in NEXT of new node.]. Step 4. If HEAD = NULL then: [ Condition to create the Linked List. ] HEAD=NewNode and return. [Add first node in list] [Add on top of existing list] Step 6. If NewNode-> Info < HEAD ->Info then: Set NewNode->NEXT = HEAD and HEAD = NewNode and return[Search the LOCATION in Middle or at end. ] [ Here CURR is the position where to insert and PREV points to previous node of the CURR node ] Step 7. Set Prev = NULL and Set Curr = NULL; Step 8. Repeat for CURR =HEAD until CURR ≠ NULL after iteration CURR = CURR ->Next if(NewNode->Info <= CURR ->Info) then: break the loop Set PREV = CURR; [ end of loop of step-7 ] [Insert after PREV node (in middle or at end) of the list] Step 9. Set NewNode->NEXT = PREV ->NEXT and Step 10. Set PREV ->NEXT= NewNode. Step 11. Exit.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Implement the algorithms in C++ program.

Algorithm 1: (Traversing a Linked List) Let LIST be a linked list in memory. This algorithm traverses LIST, applying an operation PROCESS to each Node/element of the LIST. HEAD points to the first node of the LIST. Pointer variable CURR points to the node currently being processed.

Step 1. Set CURR = HEAD. [Initializes pointer CURR.]

Step 2. Repeat Steps 3 and 4 while CURRNULL.

Step 3. Apply PROCESS to CURR -> INFO.

Step 4. Set CURR = CURR -> NEXT [CURR now points to the next node.] [End of Step-2 loop.]

Step 5. End

 

Algorithm2: INSERT( ITEM)

NOTE: Here it is needed that all the time, LIST should remains in the sorted order using Info part of the Node. To Insert / Enqueue a new node in the LIST, first LIST will be searched (using Info of Nodes) to find its LOCATION ( where to insert new Node). This exercise makes it possible that every new node has the probability to insert at the beginning, in the middle or at the end of LIST. CURR is a pointer points to the node currently being processed and PREV is a pointer pointing to previous node of the current node. [This algorithm adds NewNodes at any position (Top, in Middle OR at End) in the List ]

Step 1. Create NewNode node for LIST in memory

Step 2. Set NewNode -> Info =ITEM. [Copies new data into INFO of new node.]

Step 3. NewNode -> Next = NULL. [Copies NULL in NEXT of new node.].

Step 4. If HEAD = NULL then: [ Condition to create the Linked List. ]

HEAD=NewNode and return. [Add first node in list] [Add on top of existing list]

Step 6. If NewNode-> Info < HEAD ->Info then:

Set NewNode->NEXT = HEAD and HEAD = NewNode and return[Search the LOCATION in Middle or at end. ] [ Here CURR is the position where to insert and PREV points to previous node of the CURR node ]

Step 7. Set Prev = NULL and Set Curr = NULL;

Step 8. Repeat for CURR =HEAD until CURRNULL after iteration CURR = CURR ->Next if(NewNode->Info <= CURR ->Info) then: break the loop

Set PREV = CURR;

[ end of loop of step-7 ]

[Insert after PREV node (in middle or at end) of the list]

Step 9. Set NewNode->NEXT = PREV ->NEXT and

Step 10. Set PREV ->NEXT= NewNode.

Step 11. Exit.

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY