Recitation 2 CS0445 Data Structures

Slides:



Advertisements
Similar presentations
Why not just use Arrays? Java ArrayLists.
Advertisements

Stacks, Queues, and Linked Lists
List Implementations That Use Arrays
Lists Chapter 8 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
AITI Lecture 19 Linked List Adapted from MIT Course 1.00 Spring 2003 Lecture 26 and Tutorial Note 9 (Teachers: Please do not erase the above note)
ArrayLists The lazy mans array. Whats the matter here? int[] list = new int[10]; list[0] = 5; list[2] = hey; list[3] = 15; list[4] = 23;
CS 206 Introduction to Computer Science II 09 / 05 / 2008 Instructor: Michael Eckmann.
CSC 205 – Java Programming II Lecture 25 March 8, 2002.
5-May-15 ArrayLists. 2 ArrayList s and arrays A ArrayList is like an array of Object s Differences between arrays and ArrayList s: Arrays have special.
CS 106 Introduction to Computer Science I 04 / 30 / 2007 Last lecture :( Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 04 / 27 / 2007 Instructor: Michael Eckmann.
Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Using a List Is Like Using a Vending.
CS 106 Introduction to Computer Science I 05 / 03 / 2010 Instructor: Michael Eckmann.
Carrano, Data Structures and Abstractions with Java, Second Edition, (c) 2007 Pearson Education, Inc. All rights reserved X Announcements.
List Implementations That Use Arrays Chapter 5. 2 Chapter Contents Using a Fixed-Size Array to Implement the ADT List An Analogy The Java Implementation.
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.
Sorted Lists and Their Implementations Chapter 12 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
CS 106 Introduction to Computer Science I 04 / 30 / 2010 Instructor: Michael Eckmann.
CS-2851 Dr. Mark L. Hornick 1 Tree Maps and Tree Sets The JCF Binary Tree classes.
Recitation 1 CS0445 Data Structures Mehmud Abliz.
1 ArrayList  Array’s are limited because we need to know the size before we use them.  An ArrayList is an extension of an array that grows and shrinks.
Generalized Containers CSIS 3701: Advanced Object Oriented Programming.
GENERICS. Generics  Classes and methods can have a type parameter (actually, more than one).  The type parameter can be any reference (class) type.
Arrays Construct array: new double[10] Store in variable of type double[] double[] data = new double[10];
CS 106 Introduction to Computer Science I 04 / 25 / 2008 Instructor: Michael Eckmann.
Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Java Class Library: The Interface.
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.
ArrayList By Neil Butcher. What is the difference between an ArrayList and an Array? An ArrayList is in many ways similar to an array, but has a few subtle.
Lists Chapter 4. 2 Chapter Contents Specifications for the ADT List Redefining the Specifications Using the ADT List Using a List Is Like Using a Vending.
Sets and Maps Computer Science 4 Mr. Gerb Reference: Objective: Understand the two basic applications of searching.
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.
Object-Oriented Programming (Java) Review Unit 1 Class Design Basic Console I/O StringTokenizer Exception UML class diagram.
Sorted Lists Chapter Chapter Contents Specifications for the ADT Sorted List Using the ADT Sorted List A Linked Implementation The Method add The.
1 The copy constructor in the BankAccounts class. Two alternatives here: /** copy constructor */ public BankAccounts(BankAccounts L){ theAccounts = L.theAccounts.clone();
19-Mar-16 Collections and ArrayLists.. 2 Collections Why use Collections. Collections and Object-Orientation. ArrayLists. Special Features. Creating ArrayLists.
Lists and Sorted Lists: various implementations Slides by Nadia Al-Ghreimil adopted from Steve Armstrong LeTourneau University Longview, TX  2007, 
CSE 143 Lecture 3 Implementing ArrayIntList reading: slides created by Marty Stepp and Hélène Martin
1 CS162: Introduction to Computer Science II Abstract Data Types.
DATA STRUCTURES 1st exam solution. Question 1(1/3) Suppose we have the ADT Bag which has the following operations: bool isEmpty(): tests whether Bag is.
Data Abstraction: The Walls
CS Data Structures Chapter 8 Lists Mehmet H Gunes
Lists Chapter 4.
An Introduction to Sorting
Linked Lists Damian Gordon.
COP 3503 FALL 2012 Shayan Javed Lecture 8
Building Java Programs
TCSS 143, Autumn 2004 Lecture Notes
Chapter 12 Sorted Lists and their Implementations
ArrayLists.
Programming in Java Lecture 11: ArrayList
Copyright ©2012 by Pearson Education, Inc. All rights reserved
List Implementations Chapter 9
Recitation 5 CS0445 Data Structures
Adapted from Pearson Education, Inc.
List Implementations Chapter 9.
Queues: Implemented using Arrays
Sorted Lists and Their Implementations
Stacks: Implemented using Linked Lists
Code Refresher Test #1 Topics:
ArrayLists 22-Feb-19.
Programming II (CS300) Chapter 02: Using Objects Java ArrayList Class
CSE 143 Lecture 3 Implementing ArrayIntList reading:
ArrayLists.
ArrayLists 27-Apr-19.
ArrayList.
Queues: Implemented using Linked Lists
Arrays and ArrayLists.
Copyright ©2012 by Pearson Education, Inc. All rights reserved
© 2016 Pearson Education, Ltd. All rights reserved.
Presentation transcript:

Recitation 2 CS0445 Data Structures Mehmud Abliz

Outline Discuss AList class and its methods add() remove() replace() getEntry() countObject() getPosition() contains()

Outline (cont.) clear() getLength() isEmpty() isFull() equals() display()

AList class AList class differs from ArrayList class of JAVA, where AList class: position numbers begin at 1 instead of 0, some method names are different

add() Returns ‘true’ if successful; other wise returns ‘false’. There are 2 ‘add’ methods add(Object newEntry): appends the specified element to the end of this list. add(int newPosition, Object newEntry): inserts the element at the specified position in this list.

remove() remove(int givenPosition): removes the element at the given position. Returns the removed element

replace() replace(int givenPosition, Object newEntry): replace the element at the given position with the new element. Returns ‘true’ if replacing is true; otherwise returns ‘false’.

getEntry() getEntry(int givenPosition): get the element at the given position. Returns the element if successful; otherwise returns ‘null’.

countObject() countObject(Object anEntry): count how many times a given element (object) is appeared in the list. Returns the number of times appeared; if the element is not in the list, returns 0.

getPosition() getPosition(Object anEntry): get the position of the given element Note that the position starts from 1, not 0. Returns the position of the element; if the element is not in the list returns -1.

contains() contains(Object anEntry): returns true if this list contains the specified element.

clear() clear(): removes all entries from the list. Actually, the only thing it does is setting the length to zero.

getLength() getLength(): gets the length (current number of entries in list).

isEmpty() isEmpty(): check to see if there is element in the list. Same implementation as getLenght() method.

isFull() isFull(): check to see if the current number of elements in the list is equal to the maximum capacity of the list. Returns ‘true’ if so; else returns ‘false’.

equals() equals(AList other): check to see if the list is equal to other list (whether length is equal, and the all the elements in the list are the same, and the order of elements are same)

display() display(): print out the elements in the list

Example myList.add(5); //add Integer myList.add(23); myList.add(2); myList.add(1,"73");//add String myList.add(3,97); myList.replace(2,"W"); myList.remove(4); myList.display();