Presentation is loading. Please wait.

Presentation is loading. Please wait.

Ordered Linked Lists using Abstract Data Types (ADT) in Java Presented by: Andrew Aken.

Similar presentations


Presentation on theme: "Ordered Linked Lists using Abstract Data Types (ADT) in Java Presented by: Andrew Aken."— Presentation transcript:

1 Ordered Linked Lists using Abstract Data Types (ADT) in Java Presented by: Andrew Aken

2 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: 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 2 Ordered Linked List Abstract Data Structure (ADT) in Java

3 Introduction 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 3 Ordered Linked List Abstract Data Structure (ADT) in Java

4 Abstract Data Types (ADTs) ADTs are “abstract” in that they are independent of a concrete implementation. An interface defines 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 4 Ordered Linked List Abstract Data Structure (ADT) in Java

5 Abstract Data Types (ADTs) 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 5 Ordered Linked List Abstract Data Structure (ADT) in Java

6 Linked Lists 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 6 Ordered Linked List Abstract Data Structure (ADT) in Java

7 Subset of OrderedList Interface public interface OrderedList extends Collection { // “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();... } 7 Ordered Linked List Abstract Data Structure (ADT) in Java

8 Ordered Linked Lists 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 add method When inserting a new value into an ordered linked list there are 4 possible scenarios 1. Insert the new value into an empty list 2. Insert the new value at the front of the list 3. Insert the new value at the end of the list 4. Insert the new value between two existing nodes 8 Ordered Linked List Abstract Data Structure (ADT) in Java

9 Ordered Linked Lists (cont.) 9 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: 1. Set prev to null and set currentNode to first 2. while (currentNode.data < newObject.data) prevNode = currentNode; currentNode = currentNode.next; 3. prevNode.next = newObject; 4. newObject.next = currentNode;

10 Conclusion 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 10 Ordered Linked List Abstract Data Structure (ADT) in Java


Download ppt "Ordered Linked Lists using Abstract Data Types (ADT) in Java Presented by: Andrew Aken."

Similar presentations


Ads by Google