Posts

Showing posts with the label CS3401

CS3401 HW 7

package trees; /** Course: CS 3401  * Section: 01  * Name: Dalibor Labudovic  * Professor: Prof. Shaw  * Assignment #: Homework #7  */  import java.math.BigDecimal; import java.util.*; //******************************************************************** // Evaluates a given expression by first converting it to a // Postfix Stack and then to an Expression Tree and then // evaluating the Expression Tree //********************************************************************  public class EvaluateExpressionTree {  public static void main(String[] args) {  Scanner input = new Scanner(System.in);  System.out.println("Enter an equation in infix notation: " + "[Ex: 10+6/3 ]");  String expression = input.nextLine();  input.close();  try {  System.out.println("Result = " + evaluateExpressionTree(expression).stripTrailingZeros().toPlainString());  }  catch (Exception ex) {  System.out.println...

CS3401 Homework Assignment 8

Image
Homework Assignment #8 Exercise #1 Modify the DisplayBinaryTree.java class given out in Sample Code #8, to add three new buttons: "Show Inorder", "Show Preorder", and "Show Postorder". Each of these buttons when pressed must pop up a JOptionPane message dialog box that shows the values in the tree listed in the proper order for the ordering controlled by that button. For instance, if the "Show Inorder" button is pressed for the following tree: Then a pop up dialog will show something like: And if the user had pressed the "Show Preorder" button, a pop up dialog will show something like the following: And if the user had pressed the "Show Postorder" button, a pop up dialog will show something like the following: You will need the following three classes in your class hierarchy in order to get your program working (they are the same ones from the last assignment, and you should not change them at all): ...

CS3401 Quiz 6

Image
Question 1 5 / 5 points Which of the following are the three  major categories  of Java  Collections ? lists, sets, maps hash tables, hash maps, hash sets arraylists, linkedlists, vectors trees, lists, maps Question 2 5 / 5 points A collection that does not impose a positional order on its elements, and does not allow duplicates is called which of the following? A hashmap A linkedlist A vector A set Question 3 5 / 5 points A collection whose elements are pairs of  keys  and  values  is called which of the following? An iterator A map A binary tree A heap Question 4 0 / 5 points Ideally, the  hash codes  of two objects  should be  which of the following: The should be equal when the objects belong to the same class, and different when the objects belong to different classes They should be equal when the objects are of the same type, and ...

CS3401 Assignment 6

Homework Assignment #6 Exercise #1 Write an implementation of a generic version of MyLinkedList.java and its methods. In addition, you must modify the MyLinkedList class in the following ways while maintaining a generic implementation of this class: Make the MyLinkedList class a doubly linked list . This means adding to the Node inner class the following field which also starts off equal to null : public Node prev; As the program works now, the " list " field in the main MyLinkedList class always points to the first element in the linked list. Add a " last " field as well that always points to the last element. public Node last; Note: this field is not stored in the Node inner class. Modify the toString() method of the MyLinkedList class so that it returns a string consisting of all of the elements of the list from first to last on one line separated by commas with "<" in the front and ">" at...

CS3401 Quiz 3

Image
        Linear  time is the class of all complexity functions that are which of the following: O(log  n ) O( n  log  n ) O( n ) O(1) Question 2 5 / 5 points If an algorithm with an input size of  n  has two separate, unnested loops, the performance of the algorithm will be which of the following: O(2) O( n ) O( n 2 ) O(2 n ) Question 3 0 / 5 points Suppose you have a list named  numbers  whose type is  ArrayList <Integer> . Then which of the following for-each loop will print out all of its elements on separate lines: ...