Download presentation
Presentation is loading. Please wait.
Published byMyrtle Murphy Modified over 8 years ago
1
Scott Grissom, copyright 2004 Ch 6 Data Structures Slide 1 Linear Data Structures Chapter 6 focuses on: Lists Stacks Queues You can skip the Array implementation of Lists. We will cover it differently.
2
Scott Grissom, copyright 2004 Ch 6 Data Structures Slide 2 Lists a sequence of objects (data) current position counter position index Common Operations void first( ) boolean contains(obj) void remove( ) add(obj) add(index, obj) Object get( ) Object get(index) int size( ) Create an interface
3
Scott Grissom, copyright 2004 Ch 6 Data Structures Slide 3 Array Implementation ignore the book’s version! public class ArrayList implements List final int FIRST = 0; final int OFF_LIST = -1; int count; int current = OFF_LIST; int head = OFF_LIST; int tail = OFF_LIST; Object data[ ]; }
4
Scott Grissom, copyright 2004 Ch 6 Data Structures Slide 4 Operations for an Array Implement and analyze each operation void first( ) O(1) boolean contains(obj) O(n) void remove( ) O(n) add(obj) O(1) add(index, obj) O(n) Object get( ) O(1) Object get(index) O(1) int size( ) O(1) Group Activities write some methods
5
Scott Grissom, copyright 2004 Ch 6 Data Structures Slide 5 Linked Structures (6.2) a number of noncontiguous nodes that know about their next member a node public class Node { private Object item; private Node next; private Node(Object obj, Node n){ item = obj; next = n; sample code Node N1 = new Node (“A”, null); Node N2 = null; Node N3 = new Node (“B”, N1); Node N4 = new Node(“C”, N3); N2.next = N3; N1.next = N4; Node temp = N3; for (int I=0; I<6; I++){ temp.println(); temp = temp.getNext();
6
Scott Grissom, copyright 2004 Ch 6 Data Structures Slide 6 List Implementation public class LinkedList implements List{ int count; Node head; Node current; Node tail; }
7
Scott Grissom, copyright 2004 Ch 6 Data Structures Slide 7 Operations & Analysis (Linked) void first( ) O(1) boolean contains(obj) O(n) void remove( ) O(n) add(obj) O(1) add(index, obj) O(n) Object get( ) O(1) Object get(index) O(n) int size( ) O(1) Group Activities write some methods
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.