DOC PREVIEW
USC CSCI 455x - Code Handout

Previewing page 1

Save
Premium Document
Do you want full access? Go Premium and unlock all 1 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Code Handout to accompany Final Exam CSCI 455 [S17 Bono] 1 [C++] Node type and ListType struct Node { string data; // Note: the node here contain a string Node * next; Node() { data = ""; next = NULL; } Node(const string & d) { data = d; next = NULL; } Node(const string & d, Node * n) { data = d; next = n; } }; typedef Node * ListType; [Java] Collections class (selected methods) The Collections class contains static methods that operate on collections. Note: ArrayList and LinkedList both implement the List interface used below. static void sort(List<ElmtType> list) Sorts the list into ascending order according to the natural ordering of its elements (i.e., using compareTo). static void sort(List<ElmtType> list, Comparator<ElementType> c) Sorts the list according to the order specified by the comparator. [Java] Comparator<Type> interface An object that can compare two objects of type Type. Has one method defined by the interface: int compare(Type object1, Type object2) Must return a negative number if object1 should come before object2, 0 if object1 and object2 are equal, or a positive number if object1 should come after object2. [Java] Comparable<Type> interface An object that can be compared to another object of the same type. Has one method defined by the interface: int compareTo(Type other) a.compareTo(b) must return a negative number if a should come before b, 0 if a and b are equal, and a positive number otherwise [Java] Arrays class copyOf method The Arrays class contains static methods that operate on arrays. static int[] copyOf(int[] original, int newLength) Copies the specified array, truncating or padding with zeros (if necessary) so the copy has the specified length. For all indices that are valid in both the original array and the copy, the two arrays will contain identical


View Full Document

USC CSCI 455x - Code Handout

Download Code Handout
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Code Handout and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Code Handout 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?