1 / 20

A Recursive List Paradigm

A Recursive List Paradigm. Jack Beidler Yaodong Bi Bob McCloskey Computing Sciences University of Scranton Scranton, PA 18510. A Recursive List Paradigm. List Paradigms A Recursive List Paradigm Examples Unfocused vs. focused paradigms

janine
Download Presentation

A Recursive List Paradigm

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. A Recursive List Paradigm Jack Beidler Yaodong Bi Bob McCloskey Computing Sciences University of Scranton Scranton, PA 18510

  2. A Recursive List Paradigm • List Paradigms • A Recursive List Paradigm • Examples • Unfocused vs. focused paradigms • From the recursive paradigm to a positional paradigm www.cs.scranton.edu/~beidler/java/

  3. List Paradigms • Lists and the Java API • Interface List and its implementations • 25 methods • Swiss Army Knif Approach (multiple paradigms) • Focused Paradigms - a few well chosen coordinated methods • Array Analogy Paradigm • Positional Paradigm (One-way) • Positional Paradigm (Two-way) • Recursive Paradigm www.cs.scranton.edu/~beidler/java/

  4. A Recursive List Paradigm • McCarthy’s LISP http://www-formal.stanford.edu/jmc/history/lisp/lisp.html • A no compromise recursive paradigm • A list: • isEmpty • or (head, tail) • head is an object • tail is a (possibly empty) sublist • A Java Implementation • 3 constructors • 6 methods • 2 utility methods www.cs.scranton.edu/~beidler/java/

  5. A Recursive List Paradigm • Constructors RecursiveList ()empty list RecursiveList (Object Head) non-empty list w empty tail RecursiveList (Object Head, RecursiveList Tail)list with tail www.cs.scranton.edu/~beidler/java/

  6. A Recursive List Paradigm • Methods boolean isEmpty() RecursiveList tailOf() Object getHead() void setHead(Object NewHead) void insert(RecursiveList List) RecursiveList remove() www.cs.scranton.edu/~beidler/java/

  7. A Recursive List Paradigm • Utility Methods void swap(RecursiveList List) String toString() www.cs.scranton.edu/~beidler/java/

  8. A Recursive List Paradigm • What about iterator support • Recursion is the traversal method www.cs.scranton.edu/~beidler/java/

  9. Examples • OrderedList Class (composed with RecursiveList) import java.util.*; class OrderedList { private Comparator c; protected RecursiveList L; OrderedList (Comparator c){ this.c = c; L = new RecursiveList(); } www.cs.scranton.edu/~beidler/java/

  10. Examples • OrderedList Class (composed with RecursiveList) … privatevoid RecInsert (Object Obj, RecursiveList List){ if(List.isEmpty() || (c.compare(Obj, List.getHead())<0)) List.insert(new RecursiveList(Obj)); else RecInsert(Obj, List.tailOf()); } publicvoid insert(Object Obj){ RecInsert(Obj, L); } www.cs.scranton.edu/~beidler/java/

  11. Examples • OrderedList Class (composed with RecursiveList) … privatevoid Recmerge (RecursiveList Source1, RecursiveList Source2, RecursiveList Merged){ if (Source1.isEmpty()) Merged.swap(Source2); elseif (Source2.isEmpty()) Merged.swap(Source1); else { if (c.compare(Source1.getHead() , Source2.getHead())<0) Merged.insert(Source1.remove()); else Merged.insert(Source2.remove()); Recmerge(Source1, Source2, Merged.tailOf()); } } www.cs.scranton.edu/~beidler/java/

  12. Examples • OrderedList Class (composed with RecursiveList) … publicvoid merge(OrderedList Source1, OrderedList Source2){ Recmerge(Source1.L, Source2.L, this.L); } public String toString(){ return L.toString(); } } www.cs.scranton.edu/~beidler/java/

  13. Examples • OrderedList Class (composed with RecursiveList) • Simplicity of insert • Simplicity of merge • What about iterator support • One moment please www.cs.scranton.edu/~beidler/java/

  14. G&T 1 Constructors 13 Methods 0 Utility Methods RecursiveList 3 Constructors 6 Methods 2 Utility methods Unfocused vs. focused paradigms www.cs.scranton.edu/~beidler/java/

  15. S 2 Constructors 14 Methods 0 Utility Methods RecursiveList 3 Constructors 6 Methods 2 Utility methods Unfocused vs. focused paradigms www.cs.scranton.edu/~beidler/java/

  16. C&P 1 Constructors 7 Methods 0 Utility Methods RecursiveList 3 Constructors 6 Methods 2 Utility methods Unfocused vs. focused paradigms www.cs.scranton.edu/~beidler/java/

  17. From the recursive paradigm to a positional paradigm • What about iteration? • What about the positional paradigm? • Constructed as an extension of the recursive paradigm. www.cs.scranton.edu/~beidler/java/

  18. From the recursive paradigm to a positional paradigm void front() void rear() void next() void prev() void append(Object O) void setObject(Object O) Object getObject() boolean currDefined() www.cs.scranton.edu/~beidler/java/

  19. From the recursive paradigm to a positional paradigm RecursiveList Order = new RecursiveList(); … RecursiveListIterator It = new RecursiveListIterator(Order); for (It.front(); It.currDefined(); It.next()) System.out.print(((Integer)It.getObject())+"\t"); System.out.println(); for (It.rear(); It.currDefined(); It.prev()) System.out.print(((Integer)It.getObject())+"\t"); System.out.println(); www.cs.scranton.edu/~beidler/java/

  20. Conclusions • Lean, mean, well focused is usually better that the Swiss Army Knife approach http://www.cs.scranton.edu/~beidler/java/OneWay/ • It is even nicer with trees • RecBinTree Class http://www.cs.scranton.edu/~beidler/java/RecBinTree/ www.cs.scranton.edu/~beidler/java/

More Related