1 / 5

Linked Lists

Linked Lists. As you arrive…please snarf today’s classwork. The Code Handout. What is the output of this code? Write A-F on the sheet. Once you have answered the questions, run the code itself in Eclipse and verify your answer. If you got any wrong, figure out where you went wrong.

stasia
Download Presentation

Linked Lists

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. Linked Lists As you arrive…please snarf today’s classwork

  2. The Code Handout • What is the output of this code? Write A-F on the sheet. • Once you have answered the questions, run the code itself in Eclipse and verify your answer. If you got any wrong, figure out where you went wrong. • The nodes (beginning with NodeX) make a list. Modify the code to add a node with data “4” to the beginning of the list and a node with data “5” to the end of the list

  3. publicclassListNode { publicintdata; publicListNodenext; } Each ListNode object has a next pointer that either points to null or to the next element in the list. head Data: 5 Next: Data: 77 Next: Data: 2 Next: null

  4. The Code Reprise • If you haven’t yet: the nodes (beginning with NodeX) make a list. Modify the code to add a node with data “4” to the beginning of the list and a node with data “5” to the end of the list • Try to write the function generateList. generateList should generate a list of n nodes, each with value. It should return a pointer to the node at the head of the list.

  5. Mysterious Code • The function addZeroAsSecondElement works, but the function addZeroAsFirstElement is broken. Figure out why if you can and fix it. • OR (if you get stuck or finish)…write addZeroAsThirdElement. Be sure your code works with lists of length 0-3 elements. • When you are finished, submit your code via Ambient

More Related