Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. binary search tree error compliation error

binary search tree error compliation error

Scheduled Pinned Locked Moved Java
helpdata-structurestestingbeta-testing
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    harshad bhatia
    wrote on last edited by
    #1

    this is the binary search tree class as you can see the class is developed using generics the problem coming is in testing methods when i m passing integer as two parameters i m not sure why the error is coming whereas the cast i feel is correct .... * * Variables: root : marks the root of the tree, null if empty * * Inner classes: * Node: implements each linked node. Defined as protected since only * descendant classes need to access it * Variables: key: polymorphic comparable key * item: polymorphic data in the node * left: reference to the left subtree * right: reference to the right subtree * Methods: Node(K thisKey, T thisItem) * Node(K thisKey, T thisItem, Node l, Node r) * * Public methods: boolean isEmpty() * void clear() * boolean find(T item) * void insert(T item) * void printPreOrder() * void printInOrder() * void printPostOrder() * * Input: none * * Output: only for regression testing * * Error handling: none * * Regression testing: a private testing method for each public method * except for find and for insert (since this is * asked for during the prac). */ public class BinarySearchTree<K extends Comparable<K>,T extends Comparable<T>> { // Invariants for the class (and all its descendandts): // (1) the tree is binary: all nodes have at most two children // (2) for every node n, they key at n is greater than the key of any left // descendant, and smaller than the key of any right descendant // (3) Corollary: no key appears twice in the tree protected Node root; protected class Node { protected K key; protected SortedLList<T> item; protected Node left; protected Node right; // Creates a new leaf node of the tree with the appropriate data // // precondition: none new // postcondition: a leaf node object is created with key data thisKey // and item thisItem // Best and worst case: O(1) protected Node(K thisKey, SortedLList<T> thisItem) { key = thisKey; item = thisItem; left = null; right = null;} // Creates a new node of the tree with the appropriate data and pointing // to the given left and right children no

    I 1 Reply Last reply
    0
    • H harshad bhatia

      this is the binary search tree class as you can see the class is developed using generics the problem coming is in testing methods when i m passing integer as two parameters i m not sure why the error is coming whereas the cast i feel is correct .... * * Variables: root : marks the root of the tree, null if empty * * Inner classes: * Node: implements each linked node. Defined as protected since only * descendant classes need to access it * Variables: key: polymorphic comparable key * item: polymorphic data in the node * left: reference to the left subtree * right: reference to the right subtree * Methods: Node(K thisKey, T thisItem) * Node(K thisKey, T thisItem, Node l, Node r) * * Public methods: boolean isEmpty() * void clear() * boolean find(T item) * void insert(T item) * void printPreOrder() * void printInOrder() * void printPostOrder() * * Input: none * * Output: only for regression testing * * Error handling: none * * Regression testing: a private testing method for each public method * except for find and for insert (since this is * asked for during the prac). */ public class BinarySearchTree<K extends Comparable<K>,T extends Comparable<T>> { // Invariants for the class (and all its descendandts): // (1) the tree is binary: all nodes have at most two children // (2) for every node n, they key at n is greater than the key of any left // descendant, and smaller than the key of any right descendant // (3) Corollary: no key appears twice in the tree protected Node root; protected class Node { protected K key; protected SortedLList<T> item; protected Node left; protected Node right; // Creates a new leaf node of the tree with the appropriate data // // precondition: none new // postcondition: a leaf node object is created with key data thisKey // and item thisItem // Best and worst case: O(1) protected Node(K thisKey, SortedLList<T> thisItem) { key = thisKey; item = thisItem; left = null; right = null;} // Creates a new node of the tree with the appropriate data and pointing // to the given left and right children no

      I Offline
      I Offline
      I am BATMAN
      wrote on last edited by
      #2

      That's a ton of text....What's the error?

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups