课程: Java Algorithms

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Binary trees in Java

Binary trees in Java

- [Instructor] In Java, we can use nodes in a binary search tree manner to work with our non-linear data efficiently. The fundamental components of a binary search tree are very similar to a linked list. We'll use a node class, but instead of a next reference, we'll have preferences to the left and right nodes. Again, we can do this because we assume that a given node will have at most two direct child nodes. Let's try it. We'll create a new class and call it node. Inside, we'll give it three attributes. A node left, a node right and a piece of data, an integer. Now this node class itself is a tree. It contains left and right trees, as well as a piece of data, it only becomes a binary search tree when we use algorithms to constrain how we insert, remove and manipulate our data. This means we'll create another class called binary search tree. We'll give it one attribute, a root node, similar to how we followed a nodes next references with the linked list structure, we can follow left…

内容