1 / 10

Ordered Linked Lists using Abstract Data Types (ADT) in Java

Ordered Linked Lists using Abstract Data Types (ADT) in Java. Presented by: Andrew Aken. Objectives. This section is designed to introduce you to the concept of ordered linked lists implemented as Java Abstract Data Types (ADTs) Once completing this section you should be able to:

oleg
Download Presentation

Ordered Linked Lists using Abstract Data Types (ADT) in Java

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. Ordered Linked Lists using Abstract Data Types (ADT) in Java Presented by: Andrew Aken

  2. Objectives Ordered Linked List Abstract Data Structure (ADT) in Java This section is designed to introduce you to the concept of ordered linked lists implemented as Java Abstract Data Types (ADTs) Once completing this section you should be able to: • Build upon your prior knowledge of linked lists and ADTs • Understand the usefulness and deficiencies of ordered linked lists • Implement an ordered linked list in Java as an ADT

  3. Introduction Ordered Linked List Abstract Data Structure (ADT) in Java Linked lists provide a method of storing arbitrary quantities of data Linked lists are efficient methods of retrieving data sequentially Ordered linked lists extend this concept by storing the data sequentially for subsequent sorted retrieval

  4. Abstract Data Types (ADTs) Ordered Linked List Abstract Data Structure (ADT) in Java ADTs are “abstract” in that they are independent of a concrete implementation. An interfacedefines the methods and their arguments. “Clients” of the interface(classes that use the interface) can be written and compiled with just the interface without being concerned about the implementation. ADTs allow us to substitute better algorithms without changing any dependent code They also allow classes to be defined independent of the data types being stored

  5. Abstract Data Types (ADTs) Ordered Linked List Abstract Data Structure (ADT) in Java Separate INTERFACE and IMPLEMENTATION • easier maintenance of large programs • build layers of abstraction • reuse software Interface: description of data type, basic operations Client: program using operations defined in interface Implementation: actual code implementing operations Client doesn’t need to know details of implementation Implementation doesn’t know details of client needs

  6. Linked Lists Ordered Linked List Abstract Data Structure (ADT) in Java Linked lists are dynamic data structures • Eliminates being bound by a predetermined number of objects (e.g., arrays) • Elements are added to the end of the list Requires methods for • constructor • first • next • add • remove • find • get & set

  7. Subset of OrderedList Interface Ordered Linked List Abstract Data Structure (ADT) in Java public interface OrderedList<E> extends Collection<E> {// “E” represents Generic attribute public abstract void add( int index, E elem ); public abstract boolean add( E elem ); public abstract E remove( int index ); public abstract boolean remove( E o ); public abstract E get( int index ); public abstract E set( int index, E element ); public abstract int indexOf( E o ); public abstract int lastIndexOf( E o ); public abstract boolean contains( E o ); public abstract int size(); public abstract boolean isEmpty(); . . . }

  8. Ordered Linked Lists Ordered Linked List Abstract Data Structure (ADT) in Java In an ordered linked list, the location of a node within the list depends upon its relative ranking with respect to the data within the other nodes Most components remain the same as linked lists except ordered lists must rewrite the addmethod When inserting a new value into an ordered linked list there are 4 possible scenarios • Insert the new value into an empty list • Insert the new value at the front of the list • Insert the new value at the end of the list • Insert the new value between two existing nodes

  9. Ordered Linked Lists (cont.) Ordered Linked List Abstract Data Structure (ADT) in Java To determine the insertion point for the new data, a simple algorithm is required (e.g., to insert the number 42 into the following list: • Set prev to null and set currentNodeto first • while (currentNode.data < newObject.data) prevNode = currentNode; currentNode = currentNode.next; • prevNode.next = newObject; • newObject.next = currentNode;

  10. Conclusion Ordered Linked List Abstract Data Structure (ADT) in Java Linked lists are relatively inefficient for storing ordered data or accessing elements They are easy to implement They are useful when the number and type of elements to be stored is arbitrary

More Related