Review for Exam 2 Cs221
Chapters 4,5,6,7


ArrayLists

            methods to add and remove an item

boolean add(int index, T obj)

T remove(int index)

Linked Lists

            adding and deleting from a single linked list

            adding and deleting from a double linked list

            Using iterators w/ linked lists

                        the Iterator class

                        instance variables

                                    Node nextItem, lastItemReturned

                                    T item

                        the constructors

                                    Takes an index arguments, returns an iterator point to the node at the index

                                    Takes no argument–returns an iterator pointing to the front of the list

                        The Iterator interfaces

                                    Think of these as being positioned between nodes in a list

They are between because there are two pointers, one pointing to currItem, and one pointing to previousItem

                                    Iterator interface– can only go forward

                                                boolean hasNext( )

                                                Object next( )

                                                void remove( )

                                    ListIterator interface – can iterate backwards and forwards

                                                hasNext, hasPrevious, nextIndex, previousIndex, next, previous


                        Look at the book exercises at the end of 4.4 and 4.5 (we did in class)


Stacks LIFO data structure

            methods: push and pop

            applications: balanced ( ), evaluate postfix, convert infix to postfix, activation records

            best way to implement? ArrayList probably

            Big O of methods?

            Java constructs encountered while looking a stack code:

                        Nested Exception class

                        Constant string of characters: OPERATORS =”+-*/”

                        Wrapper classes

                        StringTokenizer class



Queues: FIFI data structure

            best way to implement: ArrayList

            void insert (object obj)                                               Object remove( )

            { back = (back+1)% MAX                                      { Object obj = A[front]

                 A[back] = obj;                                                         front = (front + 1)% MAX;

                size++                                                                       size –

            }                                                                                  }


            Application: simulations


Recursion

            Be able to walk thru code

            Algorithms we looked at

Binary search–know how it works, its time complexity

Euclid’s algorithm

            Be able to write simple recursive methods

                        know the base case

                        know the rule to make the problem smaller