Presentation is loading. Please wait.

Presentation is loading. Please wait.

COSC 2007 Data Structures II Dr Dave Goforth FA 377 (705)675-1151x2316

Similar presentations


Presentation on theme: "COSC 2007 Data Structures II Dr Dave Goforth FA 377 (705)675-1151x2316"— Presentation transcript:

1 COSC 2007 Data Structures II Dr Dave Goforth FA 377 dgoforth@cs.laurentian.ca (705)675-1151x2316 http://www.cs.laurentian.ca/dgoforth/cosc2007/outline.html (local)

2 Course Objectives Abstract Data Types (ADTs) for collections of Objects JAVA 5.0 generic Collections classes Non-linear data structures that implement ADTs Design of applications using ADTs

3 Course Organization 6 programming assignments36% due Thursday, 10:30 AM every two weeks 1 midterm examination (2 hours)24% Tuesday June 26 – 10:00 – 11:55 AM 1 final examination (3 hours)40% Tutorial? 12:00 – 12:30 after lecture?

4 Review linked structures object-oriented implementation concepts linear data structures recursion

5 Linked lists - references variables of an object type contain addresses or references to objects Point p; p = new Point(5,-2); p p x y 5 -2

6 Linked lists - nodes nodes are objects that contain references to objects of their own type class Node { int data; Node next; } Node n1, n2; n1 = new Node(3,null); n2 = new Node(5,n1); n2 data next 5 data next 3 n1

7 Doubly-linked lists Why? – bi-directional movement in list Effect on implementation – maintain one reference to ‘current’ – no need for ‘previous’ reference BUT… – insertion and deletion more complex

8 Nodes for doubly-linked lists prev and next Node references current may be only reference into list data next -5 prev data next 90 prev data next 34 prev data next prev data next prev current

9 Nodes for doubly-linked lists head and tail of list identified by null references data next -5 prev data next 90 prev data next 34 prev current (head)(tail)

10 Inserting new Node before or after current? four links to manage data next -5 prev data next 90 prev data next 34 prev current data next 14 prev

11 Deleting a node data next -5 prev data next 90 prev data next 34 prev data next prev data next prev current current Node or before or after? four links to manage ?? ?

12 on empty list on list with one Node at one end of list Operations: Special cases data next -8 prev data next 23 prev data next 91 prev

13 operations at current node -get data, update data -insert node, delete node operations on current reference -move forward, backward, head, tail operations on list -iterate Object-oriented design Doubly-linked List methods

14 Assignment 1 - text editor linked structures recursion object-oriented implementation concepts linear data structures testing

15 Assignment 1 - text editor Evalulation code javadoc documentation testing Submission web-based automated submission May 10, 10:30 AM value 6% email

16 The editor – ed, the line editor text is stored in a doubly-linked list of Strings (no wrap-around from line to line) changes to text occur at current line by commands at console three kinds of operation: 1.movement to another line 2.changes to text in list of Strings 3.file management

17 The editor – ed, updated version text is displayed in a JFrame display is updated as changes occur (still at the console) file management is by JFileChooser Assignment 1 (local)

18 Recursion problem decomposition –rewrite problem in terms of a reduced version of itself method structure –base case –recursive case

19 Recursion example problem decomposition –tired old example: factorial method structure public static int F(int n) { if (n<0) throw new IllegalArgumentException(); if (n>1) return n * F(n-1); return 1; }

20 Recursion in assignment no iterative structures can be used in this assignment –no “ for ” –no “ while ” –no “ do…while ” use recursive methods instead

21 Recursion in assignment - example public Node getHead() { Node at = this; while (at.prev != null) at = at.prev; return at; } current = current.getHead(); public class Node { int data; Node next, prev; }

22 Recursion in assignment - example public Node getHead() { if (prev == null) return this; return prev.getHead(); } public class Node { int data; Node next, prev; } current = current.getHead();

23 Static and instance methods Problem: case when current is null Static version: current = current.getHead(); current = Node.getHead(current);


Download ppt "COSC 2007 Data Structures II Dr Dave Goforth FA 377 (705)675-1151x2316"

Similar presentations


Ads by Google