L8_List - Implementing the List ADT In this lecture we...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Implementing the List ADT In this lecture we shall discuss how the list ADT can be implemented. Page 1 of 23 * The List ADT interface class public interface List { public int head(); public List tail(); public boolean isEmpty(); } Page 2 of 23 The Empty List The implementation of Empty Lists is simple and is inde- pendent of the implementation of Cons. public class EmptyList implements List { public int head() { throw new HeyException(); } public List tail() { throw new HeyException(); } public boolean isEmpty() { return true; } } Page 3 of 23 Concrete Implementation of the List ADT We shall discuss two different concrete implementations of the Cons. y Version 1.0: Using Arrays [5,7,6] 5 7 6 y Version 2.0: Using Linked Lists [5,7,6] 5 7 6 Page 4 of 23 Concrete Implementation of the List ADT (Version 2.0) In version 2.0, we use linked lists to implement list. public class Cons implements List { private int Head; [5,7,6] private List Tail; Cons(int H, List T) { … } public int head() { … } public List tail() { … } public boolean isEmpty() { 5 7 6 return false; } } Page 5 of 23 Cons(int H, List T) { this.Head = H; this.Tail = T; new Cons(8, [5,6,7]) } 8 H 8 5 6 7 T Page 6 of 23 Cons(int H, List T) { this.Head = H; this.Tail = T; new Cons(2, [4]) } 2 H 2 4 T Page 7 of 23 Cons(int H, List T) { this.Head = H; this.Tail = T; new Cons(5, ) } 5 H 5 T Page 8 of 23...
View Full Document

Page1 / 23

L8_List - Implementing the List ADT In this lecture we...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online