List data type(ADT). Lists Elements : a 1,a 2,a 3,… a i-1,a i, a i+1,…a n Null List contains: 0 elements Types of Operations on list 1.Insertion 2.Deletion.

Slides:



Advertisements
Similar presentations
Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Advertisements

Collections Chapter Java Collection Frameworks The Java collection framework is a set of utility classes and interfaces. Designed for working with.
Data Structures A data structure is a collection of data organized in some fashion that permits access to individual elements stored in the structure This.
Chapter 6 The Collections API. Simple Container/ Iterator Simple Container Shape [] v = new Shape[10]; Simple Iterator For( int i=0 ; i< v.length ; i++)
Collections Framework A very brief look at Java’s Collection Framework David Davenport May 2010.
CSC 205 – Java Programming II Lecture 25 March 8, 2002.
Collections Sets - no duplicates Lists - duplicates allowed Maps - key / value pairs A collection is an Object which contains other Objects. There are.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L11 (Chapter 20) Lists, Stacks,
Java Collections Framework COMP53 Oct 24, Collections Framework A unified architecture for representing and manipulating collections Allows collections.
15-Jun-15 Lists in Java Part of the Collections Framework.
1 L41 Collections (1). 2 OBJECTIVES  What collections are.  To use class Arrays for array manipulations.  To use the collections framework (prepackaged.
What Is a Collection?  A collection (sometimes called a container) is simply an object that groups multiple elements into a single unit.  Collections.
24-Jun-15 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L15 (Chapter 22) Java Collections.
Unit 291 Java Collections Framework: Interfaces Introduction to the Java Collections Framework (JCF) The Comparator Interface Revisited The Collection.
Vectors. Vectors and arrays A Vector is like an array of Object s Differences between arrays and Vector s: –Arrays have special syntax; Vector s don’t.
Collections The objectives of this chapter are: To outline the Collections infrastructure in Java To describe the various collection classes To discuss.
Lists in Java Part of the Collections Framework. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection.
1 ADTs, Collection, Iterable/Iterator Interfaces Collections and the Java Collections API The Collection Interface and its Hierarchy The Iterable and Iterator.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 20 Lists, Stacks, Queues, and Priority.
12-Jul-15 Lists in Java Part of the Collections Framework.
The Collections Framework A Brief Introduction. Collections A collection is a structured group of objects –An array is a kind of collection –A Vector.
1 Frameworks Part 2. 2 Collections Framework Java API contains library of useful data structures Collections library also serves as framework for adding.
Chapter 19 Java Data Structures
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 22 Lists, Stacks, Queues, and Priority.
Java's Collection Framework
1 Collection, Iterable, and Iterator Interfaces The Collection Interface and its Hierarchy The Iterable and Iterator Interfaces For-each Loops with Iterable.
SEG4110 – Advanced Software Design and Reengineering TOPIC G Java Collections Framework.
Java Collections Framework A presentation by Eric Fabricant.
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
Collections in Java. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection with no duplicates SortedSet.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
The Java Collections Framework (JCF) Introduction and review 1.
Data Design and Implementation. Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items.
Chapter 18 Java Collections Framework
Data structures Abstract data types Java classes for Data structures and ADTs.
1 Chapter 17 Object-Oriented Data Structures. 2 Objectives F To describe what a data structure is (§17.1). F To explain the limitations of arrays (§17.1).
Collections in Java. 2 Collections Hierarchy > ArrayListVector Stack LinkedList > Arrays Collections.
The Java Collections Framework Based on
3-February-2003cse Collections © 2003 University of Washington1 Java Collections CSE 403, Winter 2003 Software Engineering
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
1 Collection, Iterable, and Iterator Interfaces The Collection Interface and its Hierarchy The Iterable and Iterator Interfaces For-each Loops with Iterable.
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
Priority Queues. Priority Queue ADT A priority queue stores a collection of entries Each entry is a pair (key, value) Main methods of the Priority Queue.
IMPLEMENTING ARRAYLIST COMP 103. RECAP  Comparator and Comparable  Brief look at Exceptions TODAY  Abstract Classes - but note that the details are.
CMSC 202 Containers and Iterators. Container Definition A “container” is a data structure whose purpose is to hold objects. Most languages support several.
Data Structures I Collection, List, ArrayList, LinkedList, Iterator, ListNode.
Arrays (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Collections Dwight Deugo Nesa Matic
Object Oriented Programming in Java Habib Rostami Lecture 7.
Implementing ArrayList Part T2 Lecture 6 School of Engineering and Computer Science, Victoria University of Wellington  Thomas Kuehne, Marcus Frean,
19-Mar-16 Collections and ArrayLists.. 2 Collections Why use Collections. Collections and Object-Orientation. ArrayLists. Special Features. Creating ArrayLists.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by.
 2016, Marcus Biel, ArrayList Marcus Biel, Software Craftsman
Chapter 20 Lists, Stacks, Queues, and Priority Queues
Implementing ArrayList Part 1
TCSS 143, Autumn 2004 Lecture Notes
Programming in Java Lecture 11: ArrayList
Chapter 20 Lists, Stacks, Queues, and Priority Queues
(Java Collections Framework) AbstractSequentialList
Collections in Java The objectives of this lecture are:
ArrayLists 22-Feb-19.
Collections Framework
Programming II (CS300) Chapter 02: Using Objects Java ArrayList Class
Part of the Collections Framework
Arrays and ArrayLists.
Java Generics & Iterators
Presentation transcript:

List data type(ADT)

Lists Elements : a 1,a 2,a 3,… a i-1,a i, a i+1,…a n Null List contains: 0 elements Types of Operations on list 1.Insertion 2.Deletion 3.Search 4.Print 5.Isempty

List  An ordered collection (also known as a sequence).  The user of this interface has precise control over where in the list each element is inserted.  The user can access elements by their integer index (position in the list), and search for elements in the list.

Contd..  List allows duplicate elements.  The List interface provides four methods for positional (indexed) access to list elements.  Lists (like Java arrays) are zero based.  Thus, iterating over the elements in a list is typically preferable to indexing through it if the caller does not know the implementation.  LIST interface is a member of the Java Collections Framework.

List interface  An interface is shown, but the implementation details are hidden.  This implementation could be using arrays or linked list.  The various classes that implements list  AbstractList, AbstractSequentialList, ArrayList, AttributeList, CopyOnWriteArrayList, LinkedList, RoleList, RoleUnresolvedList, Stack, Vector

Implementing list using arrays Simple implementation is Arrays Size =Max N j A

N j A Insert(x,j) { For(k=size-1,k>j;k--) { A[k+1]=A[k]; } A[j]=x; Size++; } Inserting

Search Two types of Search functions 1.Find the element and return position. 1.Eg find(x); return the element x postion in the list 2.Find the element of given position. 1.Eg. Find_k th (p) which return k th element

Algorithm for find(x) find (x){ if (a[I]==x) print(i) /* Print the position of the element found */ } N j A Searching

Delete(x) { Pos=findpos(x); For(k=pos,k<size;k++) A[k]=a[k+1]; Size--; } Deleting x N Pos A

 Whenever we insert an element we increase size, i.e. size++;  Whenever we Delete an element we decrease size by one. i.e. size--;  Size we are taking should not exceed Max_size

List(ADT) operations.  add(); Appends an element to the end of the list.  Add(int index,E element); inserts the element at the specified position in the list.  addAll(Collection c); Append all of the elements in the collection to the end of the list.  addAll(int index, collection c); Inserts all the elements in the collection in to the list starting from the specified index.  Clear(); Removes all the elements from the list.  Contains (Object o); Retuns true if the list contains specified element.  containsAll(collection c); Returns true if the list contains all of the elements in the collection.

Contd…  equals(object e); Compares specified object with list for equality.  get(index e); Returns the element at the specified index.  hashCode(); Returns the hashcode for the list.  indexOf(Object o); Returns the index of first occurrence of the element o, returns -1 if not present.  isEmpty(); Returns true if the list contains no elements.  Remove(int index); Removes the element at the specified index); removeAll(Collection c); Remove all the elements from the list that are contained in the collection. toArray(); Returns the array of elements of the list.

Array List(ADT)  Resizable-array implementation of the List interface.  Implements all optional list operations, and permits all elements, including null.  In addition to implementing the List interface, this class provides methods to manipulate the size of the array that is used internally to store the list.

Contd..  Each ArrayList instance has a capacity.  The capacity is the size of the array used to store the elements in the list.  It is always at least as large as the list size.  As elements are added to an ArrayList, its capacity grows automatically.