

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Exam; Class: ALGS/DATA STRUCTURES; Subject: COMPUTER SCIENCE; University: Clemson University; Term: Fall 2005;
Typology: Exams
1 / 2
This page cannot be seen from the preview
Don't miss anything!


public My1DTree (int x[]) { // ... your code ... } // My1DTree
public String preorder () { public String inorder () { // ... your code ... // ... your code ... } // preorder } // inorder public String postorder () { public String levelorder () { // ... your code ... // ... your code ... } // postorder } // levelorder
public static void main(String args[]) { // -1 indicates that an array element is empty int node[] = { -1, 1, 2, 3, 4, 5, 6, 7, -1, -1, -1, -1, -1 }; System.out.print("Array contents: "); for (int i=0; i<node.length; i++) System.out.print(node[i] + ", "); System.out.println("");; My1DTree t = new My1DTree(node); System.out.println("Preorder: " + t.preorder()); System.out.println("Inorder: " + t.inorder()); System.out.println("Postorder: " + t.postorder()); System.out.println("Levelorder: " + t.levelorder()); } // end main
Array contents: -1, 1, 2, 3, 4, 5, 6, 7, -1, -1, -1, -1, -1, Preorder: 1 2 4 5 3 6 7 Inorder: 4 2 5 1 6 3 7 Postorder: 4 5 2 6 7 3 1 Levelorder: 1 2 3 4 5 6 7