This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: COMP 250 Winter 2010 lecture 6 linked lists January 18, 2010 Abstract Data Types (ADT) In the previous two lectures, I sketched out linked list data structures (singly and doubly) and some of the methods that are used to manipulate them. Notice that it was possible to define the data structures and the methods (such as addFirst( node) or remove(i)) without saying how they were implemented. When we define a data structure and the operations that we perform on it but we dont write code in a specific programming language, we are speaking about an abstract data type or ADT. (The term ADT sounds like it is mathematically well defined thing, like a derivative in Calculus or a matrix in Linear Algebra. But its not.) We will define ADTs for many data structures throughout this course, so you should be familiar with the term. Java classes for arrays and lists You have seen in COMP 202 that Java allows you to declare arrays, and these arrays can have either primitive or reference type, e.g. int arrayOfInts = new int[desiredSize]; : Student arrayofStudents = new Student[numStudents]; In addition to getting and setting values, there are many other operations that one typically wants to do with arrays, such as print out all the elements, or make a copy, or fill in a range of values. Java has classes Array and Arrays which provide some basic methods. If you instantiate an array using one of these classes instead of the most basic array shown above, you can use these methods and save yourself some coding. (Check out the Java API to see what these methods are http://java.sun.com/javase/6/docs/api ) ArrayList These array classes might not be powerful enough for your needs, though. If you are using an array to maintain a list (not a linked list !) then you will want to have methods for adding andarray to maintain a list (not a linked list !...
View Full Document