adt - The List, Stack, and Queue ADTs Abstract data type...

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

View Full Document Right Arrow Icon
The List, Stack, and Queue ADTs Abstract data type (ADT): An ADT is a set of objects together with a set operations to be performed on these objects. An ADT corresponds to (one or more) classes in an OO language such as C++ and Java. There may be more than one implementation for the same ADT, with different advantages in terms of efficiency, ease of use, ease of implementation. We will review the ADTs for lists, stacks, and queues, mainly based on array or linked list implementations. We will also study some typical applications of these ADTs to learn when to use them.
Background image of page 1

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

View Full DocumentRight Arrow Icon
The List ADT: A list of objects A 1 , A 2 , …, A n , where n is the size of the list. Some typical operations include find , insert , remove , findKth , printList , makeEmpty . An array implementation requires Θ ( n ) time for insert and remove operations in the worst case. A linked list implementation offers the flexibility of dynamically growing the list and of O(1) time insert and remove operations (assuming the position in the list is known). remove insert
Background image of page 2
Programming Details in Linked List Implementation: Use three classes for the List ADT: (1) ListNode (for the individual nodes, or objects, in the list); (2) LinkedList (for the list object itself consisting of the nodes); and (3) LinkedListItr (for the current location in a LinkedList object, in a particular application). Each class consists of one or more constructor functions. The ListNode class contains two member variables: element for the “data” field and next for the link field lining to the next node in the list.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Linked List Implementation (cont’d): The LinkedListItr class contains functions isPastEnd , retrieve , advance ; and contains a member variable current for the current location in a LinkedList object. The LinkedList class may use a dummy header node to be the first node in the list which somewhat simplifies the insert function (thus, an “empty” list contains the header node as the only node in the list). The functions included in the class are find , remove , findPrevious , and insert . Variations of linked list implementations include doubly linked lists – each node uses two link fields to link to the two neighboring nodes in the list, respectively; and circular linked lists – the last node in the list is linked to the front of the list, eliminating the header node.
Background image of page 4
Two Applications of Linked Lists: (1) Polynomials (in a single variable x ) – use nodes to represent the non-zero terms arranged in decreasing order of the exponents; typical operations include: constructor (initialize the zero polynomial in constant time); add (in O( m + n ) time for two polynomials of m and n terms, respectively); and multiply (in O( mn (min( m,n )) time for two polynomials of m and
Background image of page 5

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

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

This document was uploaded on 06/13/2011.

Page1 / 17

adt - The List, Stack, and Queue ADTs Abstract data type...

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

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