objectives
play

Objectives: Discuss linked lists Syntax Implementation Linked - PowerPoint PPT Presentation

Linked List Objectives: Discuss linked lists Syntax Implementation Linked List Characteristics: A collection Holds objects to store, retreive and manipulate Java Library LinkedList Store type Object


  1. Linked List • Objectives: – Discuss linked lists • Syntax • Implementation

  2. Linked List • Characteristics: – A collection • Holds objects to store, retreive and manipulate – Java Library • LinkedList • Store type Object • In package java.Util • Definition: – It is a data structure including a list of nodes so that each node is composed of the object and a reference to another node.

  3. Linked List • We must declare the class Node class Node { <ObjectType> <ObjectName>; Node link; } – Example a Node of a Rational umber .

  4. Linked List • Example a Node of a Rational number . class RationalNode { Rational myRat; RationalNode link; }

  5. Linked List • Declaration: – Syntax RatNode rPtr; – Meaning: • Allocate a memory to hold a reference of a RatNode • NO RatNode is created therefore, the reference is null – Instantiate: rPtr = new RatNode();

  6. Constructor • Constructor RatNode ( Rational r, RatNode lPtr) { myRat = r; link = lPtr; } • Invoke new RatNode( new Rational(2,3), null)

  7. Linked List • Look at this instruction RatNode head = new RatNode(new Rational(2,3), null); – A new object 2/3 (Rational) is created – A new object of RatNode is created – The reference of RatNode is stored in head .

  8. Linked List • Look at this instruction RatNode head = new RatNode(new Rational(2,3), head); – Compare this instruction to the one before.

  9. Linked List • Loop For (int j= 0; j < max; j++) { // create a new object from Rational class, // this new object must have a reference in r // analyze this instruction head = new RatNode(r, head); }

  10. Linked List summary – store many objects with references – are created by new

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend