From d7dd93e3ad431005e39992df5a36bfa463641560 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 9 Feb 2018 10:43:06 +0100 Subject: [PATCH] Add the binary tree class code skeleton. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- Arbres/ArbreBinaire.java | 77 ++++++++++++++++++++++++++++++++++ Arbres/Makefile | 89 ++++++++++++++++++++++++++++++++++++++++ Listes/Liste.java | 2 +- 3 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 Arbres/ArbreBinaire.java create mode 100644 Arbres/Makefile diff --git a/Arbres/ArbreBinaire.java b/Arbres/ArbreBinaire.java new file mode 100644 index 0000000..8365312 --- /dev/null +++ b/Arbres/ArbreBinaire.java @@ -0,0 +1,77 @@ + +/** + * Binary tree class. + * A binary tree is a ordered value tree with only two childs by node + */ +public class ArbreBinaire { + + private class IntNode { + private int data; + private IntNode leftIntNode; + private IntNode rightIntNode; + + IntNode(int value) { + setData(value); + setLeftNode(null); + setRightNode(null); + } + + IntNode(int value, IntNode leftNode, IntNode rightNode) { + setData(value); + setLeftNode(leftNode); + setRightNode(rightNode); + } + + private int getData() { + return data; + } + + private void setData(int value) { + data = value; + } + + private IntNode getLeftNode() { + return leftIntNode; + } + + private void setLeftNode(IntNode leftNode) { + leftIntNode = leftNode; + } + + private IntNode getRightNode() { + return rightIntNode; + } + + private void setRightNode(IntNode rightNode) { + rightIntNode = rightNode; + } + + } + + private IntNode rootNode; + + ArbreBinaire() { + setRootNode(null); + } + + private void setRootNode(IntNode node) { + rootNode = node; + } + + private IntNode getRootNode() { + return rootNode; + } + + private boolean isEmpty() { + return (getRootNode() == null); + } + + public void inserer(int value) { + + } + + public void supprimer(int value) { + + } + +} diff --git a/Arbres/Makefile b/Arbres/Makefile new file mode 100644 index 0000000..0d2af56 --- /dev/null +++ b/Arbres/Makefile @@ -0,0 +1,89 @@ +# define compiler and compiler flag variables +# define a variable for compiler flags (JFLAGS) +# define a variable for the compiler (JC) +# define a variable for the Java Virtual Machine (JVM) + +JFLAGS = -g +JC = javac +JVM = java + +# +# Clear any default targets for building .class files from .java files; we +# will provide our own target entry to do this in this makefile. +# make has a set of default targets for different suffixes (like .c.o) +# Currently, clearing the default for .java.class is not necessary since +# make does not have a definition for this target, but later versions of +# make may, so it doesn't hurt to make sure that we clear any default +# definitions for these +# + +.SUFFIXES: .java .class + + +# +# Here is our target entry for creating .class files from .java files +# This is a target entry that uses the suffix rule syntax: +# DSTS: +# rule +# DSTS (Dependency Suffix Target Suffix) +# 'TS' is the suffix of the target file, 'DS' is the suffix of the dependency +# file, and 'rule' is the rule for building a target +# '$*' is a built-in macro that gets the basename of the current target +# Remember that there must be a < tab > before the command line ('rule') +# + +.java.class: + $(JC) $(JFLAGS) $*.java + + +# +# CLASSES is a macro consisting of N words (one for each java source file) +# When a single line is too long, use \ to split lines that then will be +# considered as a single line. For example: +# NAME = Camilo \ + Juan +# is understood as +# NAME = Camilo Juan + +CLASSES = \ + ArbreBinaire.java + +# +# MAIN is a variable with the name of the file containing the main method +# + +MAIN = ArbreBinaire + +# +# the default make target entry +# for this example it is the target classes + +default: classes + + +# Next line is a target dependency line +# This target entry uses Suffix Replacement within a macro: +# $(macroname:string1=string2) +# In the words in the macro named 'macroname' replace 'string1' with 'string2' +# Below we are replacing the suffix .java of all words in the macro CLASSES +# with the .class suffix +# + +classes: $(CLASSES:.java=.class) + + +# Next two lines contain a target for running the program +# Remember the tab in the second line. +# $(JMV) y $(MAIN) are replaced by their values + +run: $(MAIN).class + $(JVM) $(MAIN) + +# this line is to remove all unneeded files from +# the directory when we are finished executing(saves space) +# and "cleans up" the directory of unneeded .class files +# RM is a predefined macro in make (RM = rm -f) +# + +clean: + $(RM) *.class diff --git a/Listes/Liste.java b/Listes/Liste.java index 711b983..d174ad5 100644 --- a/Listes/Liste.java +++ b/Listes/Liste.java @@ -44,7 +44,7 @@ public class Liste { private boolean isEmpty() { - return headNode == null; + return getHeadNode() == null; } private int getSize() { -- 2.34.1