18List - ITI 1121. Introduction to Computing II * Marcel...

Info iconThis preview shows pages 1–8. 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: ITI 1121. Introduction to Computing II * Marcel Turcotte School of Information Technology and Engineering Version of March 14, 2011 Abstract Abstract Data Types (ADTs): List * These lecture notes are meant to be looked at on a computer screen. Do not print them unless it is necessary. Definitions A List is a linear abstract data type that places no restrictions on accessing the data; inspections, insertions and deletions can occur at any position. The basic operations of a List are: int size(): returns the number of elements, the length of an empty list is 0; E get( int index ): an access method that allows to inspect the content of any position. What is the index of the first element, 0 or 1? Similarly to arrays, the first element is found at position 0; add( int index, E o ): an element can be added at any position of a list; remove( int index ): similarly, an element can be removed by position or by content. List s are more general than Stack s and Queue s; which can be implemented with help of a List . public interface List<E> { 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(); } This interface declares only a subset of the methods listed by java.util.List; Implementations ArrayList; LinkedList; Singly linked list; Doubly linked list; Dummy node; Iterative list processing (Iterator); Recursive list processing. New concepts will be introduced as needed in order to improve the efficiency of the implementation. Efficiency is measured in terms of execution speed or memory usage , we will mainly focus on execution speed. Singly Linked List The simplest of the linked list implementations is the singly linked list ( SinglyLinkedList ). Our implementation will use a static nested class, called Node here. Obviously, the type of the reference value is E . Each node of the list holds a value and is connected to its successor. private static class Node<E> { private E value; private Node<E> next; private Node( E value, Node<E> next ) { this.value = value; this.next = next; } } The class SinglyLinkedList has an instance variable that designates the first element of the list, well call this variable head . This nested class is sometimes called Elem or Entry . addFirst( E o ) (1/2) Inserting an element at the front of a list involves 1) creating a new node and 2) adding the node to the list. We distinguish two cases, the list is empty or not....
View Full Document

Page1 / 84

18List - ITI 1121. Introduction to Computing II * Marcel...

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

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