diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3bde461 --- /dev/null +++ b/.gitignore @@ -0,0 +1,35 @@ +# Created by .ignore support plugin (hsz.mobi) +### Java template +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +.gitignore +.idea/ +JavaStudy.iml +bin/com/duwei/designpattern/singleton/StaticInnerSingleton$1.class +bin/com/duwei/multythread/create/ +bin/com/duwei/multythread/future/FutureCallableDemo$Task.class +bin/com/duwei/multythread/future/FutureCallableDemo.class +bin/com/duwei/multythread/interrupt/ +bin/com/duwei/multythread/lock/ +bin/com/duwei/thinkingjava/innerclass/PrivateInnerClassTest$1.class diff --git a/bin/com/alibaba/Banker.class b/bin/com/alibaba/Banker.class deleted file mode 100644 index 6168118..0000000 Binary files a/bin/com/alibaba/Banker.class and /dev/null differ diff --git a/bin/com/alibaba/Test_1$Value.class b/bin/com/alibaba/Test_1$Value.class deleted file mode 100644 index 1bd4fe6..0000000 Binary files a/bin/com/alibaba/Test_1$Value.class and /dev/null differ diff --git a/bin/com/alibaba/Test_1.class b/bin/com/alibaba/Test_1.class deleted file mode 100644 index 4e16266..0000000 Binary files a/bin/com/alibaba/Test_1.class and /dev/null differ diff --git a/bin/com/alibaba/Test_2.class b/bin/com/alibaba/Test_2.class deleted file mode 100644 index 4ac5323..0000000 Binary files a/bin/com/alibaba/Test_2.class and /dev/null differ diff --git a/bin/com/baidu/PrintAB.class b/bin/com/baidu/PrintAB.class deleted file mode 100644 index c8baf25..0000000 Binary files a/bin/com/baidu/PrintAB.class and /dev/null differ diff --git a/bin/com/duwei/classloading/ConstClass.class b/bin/com/duwei/classloading/ConstClass.class deleted file mode 100644 index ecd0ade..0000000 Binary files a/bin/com/duwei/classloading/ConstClass.class and /dev/null differ diff --git a/bin/com/duwei/classloading/StaticTest.class b/bin/com/duwei/classloading/StaticTest.class deleted file mode 100644 index 4e796fe..0000000 Binary files a/bin/com/duwei/classloading/StaticTest.class and /dev/null differ diff --git a/bin/com/duwei/classloading/SubClass.class b/bin/com/duwei/classloading/SubClass.class deleted file mode 100644 index b8f0a0f..0000000 Binary files a/bin/com/duwei/classloading/SubClass.class and /dev/null differ diff --git a/bin/com/duwei/classloading/SuperClass.class b/bin/com/duwei/classloading/SuperClass.class deleted file mode 100644 index 8a8a246..0000000 Binary files a/bin/com/duwei/classloading/SuperClass.class and /dev/null differ diff --git a/bin/com/duwei/classloading/Test.class b/bin/com/duwei/classloading/Test.class deleted file mode 100644 index 3b65a4d..0000000 Binary files a/bin/com/duwei/classloading/Test.class and /dev/null differ diff --git a/bin/com/duwei/classloading/classloader/AppClassLoader.class b/bin/com/duwei/classloading/classloader/AppClassLoader.class deleted file mode 100644 index dce379d..0000000 Binary files a/bin/com/duwei/classloading/classloader/AppClassLoader.class and /dev/null differ diff --git a/bin/com/duwei/classloading/classloader/BootStrapLoader.class b/bin/com/duwei/classloading/classloader/BootStrapLoader.class deleted file mode 100644 index 982ab3b..0000000 Binary files a/bin/com/duwei/classloading/classloader/BootStrapLoader.class and /dev/null differ diff --git a/bin/com/duwei/classloading/classloader/ClassLoaderTest.class b/bin/com/duwei/classloading/classloader/ClassLoaderTest.class deleted file mode 100644 index f07a7c5..0000000 Binary files a/bin/com/duwei/classloading/classloader/ClassLoaderTest.class and /dev/null differ diff --git a/bin/com/duwei/classloading/classloader/CustomClassLoader.class b/bin/com/duwei/classloading/classloader/CustomClassLoader.class deleted file mode 100644 index a66cbb0..0000000 Binary files a/bin/com/duwei/classloading/classloader/CustomClassLoader.class and /dev/null differ diff --git a/bin/com/duwei/classloading/classloader/ExtensionClassLoader.class b/bin/com/duwei/classloading/classloader/ExtensionClassLoader.class deleted file mode 100644 index b53ce2d..0000000 Binary files a/bin/com/duwei/classloading/classloader/ExtensionClassLoader.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/abstractfactory/Button.class b/bin/com/duwei/designpattern/abstractfactory/Button.class deleted file mode 100644 index cabf733..0000000 Binary files a/bin/com/duwei/designpattern/abstractfactory/Button.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/abstractfactory/Client.class b/bin/com/duwei/designpattern/abstractfactory/Client.class deleted file mode 100644 index c42b482..0000000 Binary files a/bin/com/duwei/designpattern/abstractfactory/Client.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/abstractfactory/ComboBox.class b/bin/com/duwei/designpattern/abstractfactory/ComboBox.class deleted file mode 100644 index 547022a..0000000 Binary files a/bin/com/duwei/designpattern/abstractfactory/ComboBox.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/abstractfactory/SkinFactory.class b/bin/com/duwei/designpattern/abstractfactory/SkinFactory.class deleted file mode 100644 index 534fa27..0000000 Binary files a/bin/com/duwei/designpattern/abstractfactory/SkinFactory.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/abstractfactory/SpringButton.class b/bin/com/duwei/designpattern/abstractfactory/SpringButton.class deleted file mode 100644 index 5294d51..0000000 Binary files a/bin/com/duwei/designpattern/abstractfactory/SpringButton.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/abstractfactory/SpringComboBox.class b/bin/com/duwei/designpattern/abstractfactory/SpringComboBox.class deleted file mode 100644 index cf97503..0000000 Binary files a/bin/com/duwei/designpattern/abstractfactory/SpringComboBox.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/abstractfactory/SpringSkinFactory.class b/bin/com/duwei/designpattern/abstractfactory/SpringSkinFactory.class deleted file mode 100644 index 6736972..0000000 Binary files a/bin/com/duwei/designpattern/abstractfactory/SpringSkinFactory.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/abstractfactory/SpringTextField.class b/bin/com/duwei/designpattern/abstractfactory/SpringTextField.class deleted file mode 100644 index 99badb7..0000000 Binary files a/bin/com/duwei/designpattern/abstractfactory/SpringTextField.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/abstractfactory/SummerButton.class b/bin/com/duwei/designpattern/abstractfactory/SummerButton.class deleted file mode 100644 index 68708f7..0000000 Binary files a/bin/com/duwei/designpattern/abstractfactory/SummerButton.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/abstractfactory/SummerComboBox.class b/bin/com/duwei/designpattern/abstractfactory/SummerComboBox.class deleted file mode 100644 index c88cd12..0000000 Binary files a/bin/com/duwei/designpattern/abstractfactory/SummerComboBox.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/abstractfactory/SummerSkinFactory.class b/bin/com/duwei/designpattern/abstractfactory/SummerSkinFactory.class deleted file mode 100644 index cdcd7d6..0000000 Binary files a/bin/com/duwei/designpattern/abstractfactory/SummerSkinFactory.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/abstractfactory/SummerTextField.class b/bin/com/duwei/designpattern/abstractfactory/SummerTextField.class deleted file mode 100644 index fe788c2..0000000 Binary files a/bin/com/duwei/designpattern/abstractfactory/SummerTextField.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/abstractfactory/TextField.class b/bin/com/duwei/designpattern/abstractfactory/TextField.class deleted file mode 100644 index 072f8e1..0000000 Binary files a/bin/com/duwei/designpattern/abstractfactory/TextField.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/abstractfactory/XMLUtil.class b/bin/com/duwei/designpattern/abstractfactory/XMLUtil.class deleted file mode 100644 index 1f325d6..0000000 Binary files a/bin/com/duwei/designpattern/abstractfactory/XMLUtil.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/adapter/BinarySearch.class b/bin/com/duwei/designpattern/adapter/BinarySearch.class deleted file mode 100644 index 7f19be1..0000000 Binary files a/bin/com/duwei/designpattern/adapter/BinarySearch.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/adapter/OperationAdapter.class b/bin/com/duwei/designpattern/adapter/OperationAdapter.class deleted file mode 100644 index bbdcf5e..0000000 Binary files a/bin/com/duwei/designpattern/adapter/OperationAdapter.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/adapter/QuickSort.class b/bin/com/duwei/designpattern/adapter/QuickSort.class deleted file mode 100644 index eea758c..0000000 Binary files a/bin/com/duwei/designpattern/adapter/QuickSort.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/adapter/ScoreOperation.class b/bin/com/duwei/designpattern/adapter/ScoreOperation.class deleted file mode 100644 index 989c77c..0000000 Binary files a/bin/com/duwei/designpattern/adapter/ScoreOperation.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/chapter2_001/Chapter2_001.class b/bin/com/duwei/designpattern/chapter2_001/Chapter2_001.class deleted file mode 100644 index b547d21..0000000 Binary files a/bin/com/duwei/designpattern/chapter2_001/Chapter2_001.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/chapter2_001/Father.class b/bin/com/duwei/designpattern/chapter2_001/Father.class deleted file mode 100644 index d3a9619..0000000 Binary files a/bin/com/duwei/designpattern/chapter2_001/Father.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/chapter2_001/Son.class b/bin/com/duwei/designpattern/chapter2_001/Son.class deleted file mode 100644 index 248c59a..0000000 Binary files a/bin/com/duwei/designpattern/chapter2_001/Son.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/factorymethod/Client.class b/bin/com/duwei/designpattern/factorymethod/Client.class deleted file mode 100644 index 41bf470..0000000 Binary files a/bin/com/duwei/designpattern/factorymethod/Client.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/factorymethod/DatabaseLogger.class b/bin/com/duwei/designpattern/factorymethod/DatabaseLogger.class deleted file mode 100644 index 920374e..0000000 Binary files a/bin/com/duwei/designpattern/factorymethod/DatabaseLogger.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/factorymethod/DatabaseLoggerFactory.class b/bin/com/duwei/designpattern/factorymethod/DatabaseLoggerFactory.class deleted file mode 100644 index f187edc..0000000 Binary files a/bin/com/duwei/designpattern/factorymethod/DatabaseLoggerFactory.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/factorymethod/FileLogger.class b/bin/com/duwei/designpattern/factorymethod/FileLogger.class deleted file mode 100644 index ff6b4f2..0000000 Binary files a/bin/com/duwei/designpattern/factorymethod/FileLogger.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/factorymethod/FileLoggerFactory.class b/bin/com/duwei/designpattern/factorymethod/FileLoggerFactory.class deleted file mode 100644 index 4943eb2..0000000 Binary files a/bin/com/duwei/designpattern/factorymethod/FileLoggerFactory.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/factorymethod/Logger.class b/bin/com/duwei/designpattern/factorymethod/Logger.class deleted file mode 100644 index 1ccaa45..0000000 Binary files a/bin/com/duwei/designpattern/factorymethod/Logger.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/factorymethod/LoggerFactory.class b/bin/com/duwei/designpattern/factorymethod/LoggerFactory.class deleted file mode 100644 index ff44fdd..0000000 Binary files a/bin/com/duwei/designpattern/factorymethod/LoggerFactory.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/simplefictory/Chart.class b/bin/com/duwei/designpattern/simplefictory/Chart.class deleted file mode 100644 index 681448e..0000000 Binary files a/bin/com/duwei/designpattern/simplefictory/Chart.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/simplefictory/ChartFactory.class b/bin/com/duwei/designpattern/simplefictory/ChartFactory.class deleted file mode 100644 index b126cb6..0000000 Binary files a/bin/com/duwei/designpattern/simplefictory/ChartFactory.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/simplefictory/Client.class b/bin/com/duwei/designpattern/simplefictory/Client.class deleted file mode 100644 index c6f55d0..0000000 Binary files a/bin/com/duwei/designpattern/simplefictory/Client.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/simplefictory/HistogramChart.class b/bin/com/duwei/designpattern/simplefictory/HistogramChart.class deleted file mode 100644 index 1d02143..0000000 Binary files a/bin/com/duwei/designpattern/simplefictory/HistogramChart.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/simplefictory/LineChart.class b/bin/com/duwei/designpattern/simplefictory/LineChart.class deleted file mode 100644 index 7ac2978..0000000 Binary files a/bin/com/duwei/designpattern/simplefictory/LineChart.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/simplefictory/PieChart.class b/bin/com/duwei/designpattern/simplefictory/PieChart.class deleted file mode 100644 index b474d6c..0000000 Binary files a/bin/com/duwei/designpattern/simplefictory/PieChart.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/singleton/DoubleLock.class b/bin/com/duwei/designpattern/singleton/DoubleLock.class deleted file mode 100644 index 2021e77..0000000 Binary files a/bin/com/duwei/designpattern/singleton/DoubleLock.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/singleton/HungryMan.class b/bin/com/duwei/designpattern/singleton/HungryMan.class deleted file mode 100644 index 00cf392..0000000 Binary files a/bin/com/duwei/designpattern/singleton/HungryMan.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/singleton/LazyMan.class b/bin/com/duwei/designpattern/singleton/LazyMan.class deleted file mode 100644 index 4651980..0000000 Binary files a/bin/com/duwei/designpattern/singleton/LazyMan.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/singleton/StaticInnerSingleton$HolderClass.class b/bin/com/duwei/designpattern/singleton/StaticInnerSingleton$HolderClass.class deleted file mode 100644 index b1c2045..0000000 Binary files a/bin/com/duwei/designpattern/singleton/StaticInnerSingleton$HolderClass.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/singleton/StaticInnerSingleton.class b/bin/com/duwei/designpattern/singleton/StaticInnerSingleton.class deleted file mode 100644 index fa4ef73..0000000 Binary files a/bin/com/duwei/designpattern/singleton/StaticInnerSingleton.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/singleton/StaticSelfInstance.class b/bin/com/duwei/designpattern/singleton/StaticSelfInstance.class deleted file mode 100644 index 3a6c9f8..0000000 Binary files a/bin/com/duwei/designpattern/singleton/StaticSelfInstance.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/state/Client.class b/bin/com/duwei/designpattern/state/Client.class deleted file mode 100644 index 4e08953..0000000 Binary files a/bin/com/duwei/designpattern/state/Client.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/state/ClosingState.class b/bin/com/duwei/designpattern/state/ClosingState.class deleted file mode 100644 index 06b4f0b..0000000 Binary files a/bin/com/duwei/designpattern/state/ClosingState.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/state/Context.class b/bin/com/duwei/designpattern/state/Context.class deleted file mode 100644 index 02cc0ee..0000000 Binary files a/bin/com/duwei/designpattern/state/Context.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/state/LiftState.class b/bin/com/duwei/designpattern/state/LiftState.class deleted file mode 100644 index 1f87922..0000000 Binary files a/bin/com/duwei/designpattern/state/LiftState.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/state/OpeningState.class b/bin/com/duwei/designpattern/state/OpeningState.class deleted file mode 100644 index 92ec504..0000000 Binary files a/bin/com/duwei/designpattern/state/OpeningState.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/state/RunningState.class b/bin/com/duwei/designpattern/state/RunningState.class deleted file mode 100644 index 0befd6d..0000000 Binary files a/bin/com/duwei/designpattern/state/RunningState.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/state/StoppingState.class b/bin/com/duwei/designpattern/state/StoppingState.class deleted file mode 100644 index e8cc6c4..0000000 Binary files a/bin/com/duwei/designpattern/state/StoppingState.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/state2/Account.class b/bin/com/duwei/designpattern/state2/Account.class deleted file mode 100644 index 06e3765..0000000 Binary files a/bin/com/duwei/designpattern/state2/Account.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/state2/AccountState.class b/bin/com/duwei/designpattern/state2/AccountState.class deleted file mode 100644 index 9961d15..0000000 Binary files a/bin/com/duwei/designpattern/state2/AccountState.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/state2/Client.class b/bin/com/duwei/designpattern/state2/Client.class deleted file mode 100644 index c39277b..0000000 Binary files a/bin/com/duwei/designpattern/state2/Client.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/state2/ConcreteState.class b/bin/com/duwei/designpattern/state2/ConcreteState.class deleted file mode 100644 index 9fd3ccd..0000000 Binary files a/bin/com/duwei/designpattern/state2/ConcreteState.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/state2/Context.class b/bin/com/duwei/designpattern/state2/Context.class deleted file mode 100644 index 16470f1..0000000 Binary files a/bin/com/duwei/designpattern/state2/Context.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/state2/NormalState.class b/bin/com/duwei/designpattern/state2/NormalState.class deleted file mode 100644 index fcf8e92..0000000 Binary files a/bin/com/duwei/designpattern/state2/NormalState.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/state2/OverdraftState.class b/bin/com/duwei/designpattern/state2/OverdraftState.class deleted file mode 100644 index dd192d9..0000000 Binary files a/bin/com/duwei/designpattern/state2/OverdraftState.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/state2/RestrictedState.class b/bin/com/duwei/designpattern/state2/RestrictedState.class deleted file mode 100644 index 8dd0869..0000000 Binary files a/bin/com/duwei/designpattern/state2/RestrictedState.class and /dev/null differ diff --git a/bin/com/duwei/designpattern/state2/State.class b/bin/com/duwei/designpattern/state2/State.class deleted file mode 100644 index 6fe5689..0000000 Binary files a/bin/com/duwei/designpattern/state2/State.class and /dev/null differ diff --git a/bin/com/duwei/encrypt/FrequencyAnalysis$1.class b/bin/com/duwei/encrypt/FrequencyAnalysis$1.class deleted file mode 100644 index 58187ae..0000000 Binary files a/bin/com/duwei/encrypt/FrequencyAnalysis$1.class and /dev/null differ diff --git a/bin/com/duwei/encrypt/FrequencyAnalysis.class b/bin/com/duwei/encrypt/FrequencyAnalysis.class deleted file mode 100644 index 0f3edc8..0000000 Binary files a/bin/com/duwei/encrypt/FrequencyAnalysis.class and /dev/null differ diff --git a/bin/com/duwei/encrypt/MessageDigestTest.class b/bin/com/duwei/encrypt/MessageDigestTest.class deleted file mode 100644 index 309e292..0000000 Binary files a/bin/com/duwei/encrypt/MessageDigestTest.class and /dev/null differ diff --git a/bin/com/duwei/encrypt/MyEncrypt.class b/bin/com/duwei/encrypt/MyEncrypt.class deleted file mode 100644 index 8de86a0..0000000 Binary files a/bin/com/duwei/encrypt/MyEncrypt.class and /dev/null differ diff --git a/bin/com/duwei/encrypt/RSA.class b/bin/com/duwei/encrypt/RSA.class deleted file mode 100644 index daafe61..0000000 Binary files a/bin/com/duwei/encrypt/RSA.class and /dev/null differ diff --git a/bin/com/duwei/file/FileOprator.class b/bin/com/duwei/file/FileOprator.class deleted file mode 100644 index 4acb24b..0000000 Binary files a/bin/com/duwei/file/FileOprator.class and /dev/null differ diff --git a/bin/com/duwei/multythread/AtomicIntegerDemo.class b/bin/com/duwei/multythread/AtomicIntegerDemo.class deleted file mode 100644 index 64b0b0b..0000000 Binary files a/bin/com/duwei/multythread/AtomicIntegerDemo.class and /dev/null differ diff --git a/bin/com/duwei/multythread/Consumer.class b/bin/com/duwei/multythread/Consumer.class deleted file mode 100644 index fbefc33..0000000 Binary files a/bin/com/duwei/multythread/Consumer.class and /dev/null differ diff --git a/bin/com/duwei/multythread/FileSearch$1.class b/bin/com/duwei/multythread/FileSearch$1.class deleted file mode 100644 index ae7cde6..0000000 Binary files a/bin/com/duwei/multythread/FileSearch$1.class and /dev/null differ diff --git a/bin/com/duwei/multythread/FileSearch.class b/bin/com/duwei/multythread/FileSearch.class deleted file mode 100644 index c9c338b..0000000 Binary files a/bin/com/duwei/multythread/FileSearch.class and /dev/null differ diff --git a/bin/com/duwei/multythread/FileSearch2$1.class b/bin/com/duwei/multythread/FileSearch2$1.class deleted file mode 100644 index ff7140a..0000000 Binary files a/bin/com/duwei/multythread/FileSearch2$1.class and /dev/null differ diff --git a/bin/com/duwei/multythread/FileSearch2.class b/bin/com/duwei/multythread/FileSearch2.class deleted file mode 100644 index 23a0542..0000000 Binary files a/bin/com/duwei/multythread/FileSearch2.class and /dev/null differ diff --git a/bin/com/duwei/multythread/Producer.class b/bin/com/duwei/multythread/Producer.class deleted file mode 100644 index f9ffd1d..0000000 Binary files a/bin/com/duwei/multythread/Producer.class and /dev/null differ diff --git a/bin/com/duwei/multythread/ProducerConsumerInJava.class b/bin/com/duwei/multythread/ProducerConsumerInJava.class deleted file mode 100644 index 13e0400..0000000 Binary files a/bin/com/duwei/multythread/ProducerConsumerInJava.class and /dev/null differ diff --git a/bin/com/duwei/multythread/ReentrantLockDemo.class b/bin/com/duwei/multythread/ReentrantLockDemo.class deleted file mode 100644 index a3ba2e5..0000000 Binary files a/bin/com/duwei/multythread/ReentrantLockDemo.class and /dev/null differ diff --git a/bin/com/duwei/multythread/ThreadDemo$1.class b/bin/com/duwei/multythread/ThreadDemo$1.class deleted file mode 100644 index b5ddee8..0000000 Binary files a/bin/com/duwei/multythread/ThreadDemo$1.class and /dev/null differ diff --git a/bin/com/duwei/multythread/ThreadDemo.class b/bin/com/duwei/multythread/ThreadDemo.class deleted file mode 100644 index a3eebf9..0000000 Binary files a/bin/com/duwei/multythread/ThreadDemo.class and /dev/null differ diff --git a/bin/com/duwei/multythread/future/CallableDemo.class b/bin/com/duwei/multythread/future/CallableDemo.class deleted file mode 100644 index cca5a22..0000000 Binary files a/bin/com/duwei/multythread/future/CallableDemo.class and /dev/null differ diff --git a/bin/com/duwei/multythread/future/Task.class b/bin/com/duwei/multythread/future/Task.class deleted file mode 100644 index 31945bc..0000000 Binary files a/bin/com/duwei/multythread/future/Task.class and /dev/null differ diff --git a/bin/com/duwei/multythread/future/Test.class b/bin/com/duwei/multythread/future/Test.class deleted file mode 100644 index 51464c2..0000000 Binary files a/bin/com/duwei/multythread/future/Test.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/FuClazz.class b/bin/com/duwei/thinkingjava/FuClazz.class deleted file mode 100644 index 1608d45..0000000 Binary files a/bin/com/duwei/thinkingjava/FuClazz.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/SubClazz.class b/bin/com/duwei/thinkingjava/SubClazz.class deleted file mode 100644 index 9f09811..0000000 Binary files a/bin/com/duwei/thinkingjava/SubClazz.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/TestClass.class b/bin/com/duwei/thinkingjava/TestClass.class deleted file mode 100644 index b3b89a9..0000000 Binary files a/bin/com/duwei/thinkingjava/TestClass.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/generictype/Erased.class b/bin/com/duwei/thinkingjava/generictype/Erased.class deleted file mode 100644 index 51d2766..0000000 Binary files a/bin/com/duwei/thinkingjava/generictype/Erased.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/ClassInFunction$1pDestination.class b/bin/com/duwei/thinkingjava/innerclass/ClassInFunction$1pDestination.class deleted file mode 100644 index 663a29b..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/ClassInFunction$1pDestination.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/ClassInFunction$Destination.class b/bin/com/duwei/thinkingjava/innerclass/ClassInFunction$Destination.class deleted file mode 100644 index 2ef53df..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/ClassInFunction$Destination.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/ClassInFunction.class b/bin/com/duwei/thinkingjava/innerclass/ClassInFunction.class deleted file mode 100644 index 152fa8d..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/ClassInFunction.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/Func.class b/bin/com/duwei/thinkingjava/innerclass/Func.class deleted file mode 100644 index 8199ec0..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/Func.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/OutterClass$1.class b/bin/com/duwei/thinkingjava/innerclass/OutterClass$1.class deleted file mode 100644 index 90cde5b..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/OutterClass$1.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/OutterClass$1PrintString.class b/bin/com/duwei/thinkingjava/innerclass/OutterClass$1PrintString.class deleted file mode 100644 index cf2b70f..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/OutterClass$1PrintString.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/OutterClass$IPrintString.class b/bin/com/duwei/thinkingjava/innerclass/OutterClass$IPrintString.class deleted file mode 100644 index 2d825a1..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/OutterClass$IPrintString.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/OutterClass$InnerClass.class b/bin/com/duwei/thinkingjava/innerclass/OutterClass$InnerClass.class deleted file mode 100644 index 608eada..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/OutterClass$InnerClass.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/OutterClass.class b/bin/com/duwei/thinkingjava/innerclass/OutterClass.class deleted file mode 100644 index 680c21f..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/OutterClass.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/OutterClassField$Chinese.class b/bin/com/duwei/thinkingjava/innerclass/OutterClassField$Chinese.class deleted file mode 100644 index df7d157..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/OutterClassField$Chinese.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/OutterClassField.class b/bin/com/duwei/thinkingjava/innerclass/OutterClassField.class deleted file mode 100644 index d670e33..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/OutterClassField.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/PrivateInnerClassTest$Inner.class b/bin/com/duwei/thinkingjava/innerclass/PrivateInnerClassTest$Inner.class deleted file mode 100644 index 6f49f04..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/PrivateInnerClassTest$Inner.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/PrivateInnerClassTest.class b/bin/com/duwei/thinkingjava/innerclass/PrivateInnerClassTest.class deleted file mode 100644 index 81dbd45..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/PrivateInnerClassTest.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/StaticInnerClassTest$InnerClass.class b/bin/com/duwei/thinkingjava/innerclass/StaticInnerClassTest$InnerClass.class deleted file mode 100644 index d813538..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/StaticInnerClassTest$InnerClass.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/StaticInnerClassTest$InnerClassInterface$TestInnerClassInterface.class b/bin/com/duwei/thinkingjava/innerclass/StaticInnerClassTest$InnerClassInterface$TestInnerClassInterface.class deleted file mode 100644 index 6a4921f..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/StaticInnerClassTest$InnerClassInterface$TestInnerClassInterface.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/StaticInnerClassTest$InnerClassInterface.class b/bin/com/duwei/thinkingjava/innerclass/StaticInnerClassTest$InnerClassInterface.class deleted file mode 100644 index 04fc218..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/StaticInnerClassTest$InnerClassInterface.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/StaticInnerClassTest.class b/bin/com/duwei/thinkingjava/innerclass/StaticInnerClassTest.class deleted file mode 100644 index 48185c8..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/StaticInnerClassTest.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/StaticTest.class b/bin/com/duwei/thinkingjava/innerclass/StaticTest.class deleted file mode 100644 index 6560aa3..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/StaticTest.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/TestInnerClass$Inner.class b/bin/com/duwei/thinkingjava/innerclass/TestInnerClass$Inner.class deleted file mode 100644 index da4d545..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/TestInnerClass$Inner.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/innerclass/TestInnerClass.class b/bin/com/duwei/thinkingjava/innerclass/TestInnerClass.class deleted file mode 100644 index 8704140..0000000 Binary files a/bin/com/duwei/thinkingjava/innerclass/TestInnerClass.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/reflect/Other.class b/bin/com/duwei/thinkingjava/reflect/Other.class deleted file mode 100644 index 47da64a..0000000 Binary files a/bin/com/duwei/thinkingjava/reflect/Other.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/reflect/OtherFather.class b/bin/com/duwei/thinkingjava/reflect/OtherFather.class deleted file mode 100644 index e7c2b74..0000000 Binary files a/bin/com/duwei/thinkingjava/reflect/OtherFather.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/reflect/This.class b/bin/com/duwei/thinkingjava/reflect/This.class deleted file mode 100644 index 3028916..0000000 Binary files a/bin/com/duwei/thinkingjava/reflect/This.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/reflect/method/StudentDemo.class b/bin/com/duwei/thinkingjava/reflect/method/StudentDemo.class deleted file mode 100644 index a4f9629..0000000 Binary files a/bin/com/duwei/thinkingjava/reflect/method/StudentDemo.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/reflect/method/TestInvoke.class b/bin/com/duwei/thinkingjava/reflect/method/TestInvoke.class deleted file mode 100644 index 00fabd4..0000000 Binary files a/bin/com/duwei/thinkingjava/reflect/method/TestInvoke.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/reflect/proxy/HunJieSuo.class b/bin/com/duwei/thinkingjava/reflect/proxy/HunJieSuo.class deleted file mode 100644 index 023ee80..0000000 Binary files a/bin/com/duwei/thinkingjava/reflect/proxy/HunJieSuo.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/reflect/proxy/Interface.class b/bin/com/duwei/thinkingjava/reflect/proxy/Interface.class deleted file mode 100644 index 546013b..0000000 Binary files a/bin/com/duwei/thinkingjava/reflect/proxy/Interface.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/reflect/proxy/ReadyInvocationHandler.class b/bin/com/duwei/thinkingjava/reflect/proxy/ReadyInvocationHandler.class deleted file mode 100644 index 8705337..0000000 Binary files a/bin/com/duwei/thinkingjava/reflect/proxy/ReadyInvocationHandler.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/reflect/proxy/RealObject.class b/bin/com/duwei/thinkingjava/reflect/proxy/RealObject.class deleted file mode 100644 index 38c201d..0000000 Binary files a/bin/com/duwei/thinkingjava/reflect/proxy/RealObject.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/reflect/proxy/SimpleProxy.class b/bin/com/duwei/thinkingjava/reflect/proxy/SimpleProxy.class deleted file mode 100644 index 222ac89..0000000 Binary files a/bin/com/duwei/thinkingjava/reflect/proxy/SimpleProxy.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/reflect/proxy/SimpleProxyDemo.class b/bin/com/duwei/thinkingjava/reflect/proxy/SimpleProxyDemo.class deleted file mode 100644 index f158cdb..0000000 Binary files a/bin/com/duwei/thinkingjava/reflect/proxy/SimpleProxyDemo.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/reflect/proxy/XiangQinInterface.class b/bin/com/duwei/thinkingjava/reflect/proxy/XiangQinInterface.class deleted file mode 100644 index 55f5cb8..0000000 Binary files a/bin/com/duwei/thinkingjava/reflect/proxy/XiangQinInterface.class and /dev/null differ diff --git a/bin/com/duwei/thinkingjava/reflect/proxy/ZhangSanXiangQinInterfaceImpl.class b/bin/com/duwei/thinkingjava/reflect/proxy/ZhangSanXiangQinInterfaceImpl.class deleted file mode 100644 index cebe679..0000000 Binary files a/bin/com/duwei/thinkingjava/reflect/proxy/ZhangSanXiangQinInterfaceImpl.class and /dev/null differ diff --git a/bin/com/duweri/interview/AllTestHere.class b/bin/com/duweri/interview/AllTestHere.class deleted file mode 100644 index 4d36559..0000000 Binary files a/bin/com/duweri/interview/AllTestHere.class and /dev/null differ diff --git a/bin/com/duweri/interview/BitCompute.class b/bin/com/duweri/interview/BitCompute.class deleted file mode 100644 index 551204e..0000000 Binary files a/bin/com/duweri/interview/BitCompute.class and /dev/null differ diff --git a/bin/com/duweri/interview/DateTest.class b/bin/com/duweri/interview/DateTest.class deleted file mode 100644 index 769e1f4..0000000 Binary files a/bin/com/duweri/interview/DateTest.class and /dev/null differ diff --git a/bin/com/duweri/interview/FinalTest.class b/bin/com/duweri/interview/FinalTest.class deleted file mode 100644 index 1b6d13c..0000000 Binary files a/bin/com/duweri/interview/FinalTest.class and /dev/null differ diff --git a/bin/com/duweri/interview/IntegerCache.class b/bin/com/duweri/interview/IntegerCache.class deleted file mode 100644 index bd0e7e1..0000000 Binary files a/bin/com/duweri/interview/IntegerCache.class and /dev/null differ diff --git a/bin/com/duweri/interview/LambdaTest$1.class b/bin/com/duweri/interview/LambdaTest$1.class deleted file mode 100644 index 5106991..0000000 Binary files a/bin/com/duweri/interview/LambdaTest$1.class and /dev/null differ diff --git a/bin/com/duweri/interview/LambdaTest.class b/bin/com/duweri/interview/LambdaTest.class deleted file mode 100644 index d0eea74..0000000 Binary files a/bin/com/duweri/interview/LambdaTest.class and /dev/null differ diff --git a/bin/com/duweri/interview/Overload.class b/bin/com/duweri/interview/Overload.class deleted file mode 100644 index bd11967..0000000 Binary files a/bin/com/duweri/interview/Overload.class and /dev/null differ diff --git a/bin/com/duweri/interview/OverloadVsOverride.class b/bin/com/duweri/interview/OverloadVsOverride.class deleted file mode 100644 index 5569159..0000000 Binary files a/bin/com/duweri/interview/OverloadVsOverride.class and /dev/null differ diff --git a/bin/com/duweri/interview/Sort.class b/bin/com/duweri/interview/Sort.class deleted file mode 100644 index 821d27c..0000000 Binary files a/bin/com/duweri/interview/Sort.class and /dev/null differ diff --git a/bin/com/duweri/interview/StringTest.class b/bin/com/duweri/interview/StringTest.class deleted file mode 100644 index f1232b5..0000000 Binary files a/bin/com/duweri/interview/StringTest.class and /dev/null differ diff --git a/bin/com/duweri/interview/SubStringTest.class b/bin/com/duweri/interview/SubStringTest.class deleted file mode 100644 index e988ddf..0000000 Binary files a/bin/com/duweri/interview/SubStringTest.class and /dev/null differ diff --git a/bin/com/duweri/interview/Test.class b/bin/com/duweri/interview/Test.class deleted file mode 100644 index 6688655..0000000 Binary files a/bin/com/duweri/interview/Test.class and /dev/null differ diff --git a/bin/com/duweri/interview/UniqueNum.class b/bin/com/duweri/interview/UniqueNum.class deleted file mode 100644 index 24b21e9..0000000 Binary files a/bin/com/duweri/interview/UniqueNum.class and /dev/null differ diff --git a/bin/com/duweri/interview/UseSwitch.class b/bin/com/duweri/interview/UseSwitch.class deleted file mode 100644 index 6a8df2c..0000000 Binary files a/bin/com/duweri/interview/UseSwitch.class and /dev/null differ diff --git a/bin/com/duweri/interview/datastructure/BinSearch.class b/bin/com/duweri/interview/datastructure/BinSearch.class deleted file mode 100644 index 182336c..0000000 Binary files a/bin/com/duweri/interview/datastructure/BinSearch.class and /dev/null differ diff --git a/bin/com/duweri/interview/datastructure/ReBuildBinaryTree$TreeNode.class b/bin/com/duweri/interview/datastructure/ReBuildBinaryTree$TreeNode.class deleted file mode 100644 index 536821a..0000000 Binary files a/bin/com/duweri/interview/datastructure/ReBuildBinaryTree$TreeNode.class and /dev/null differ diff --git a/bin/com/duweri/interview/datastructure/ReBuildBinaryTree.class b/bin/com/duweri/interview/datastructure/ReBuildBinaryTree.class deleted file mode 100644 index 17ea80b..0000000 Binary files a/bin/com/duweri/interview/datastructure/ReBuildBinaryTree.class and /dev/null differ diff --git a/bin/com/duweri/interview/datastructure/Sort.class b/bin/com/duweri/interview/datastructure/Sort.class deleted file mode 100644 index 92fedd6..0000000 Binary files a/bin/com/duweri/interview/datastructure/Sort.class and /dev/null differ diff --git a/bin/com/duweri/interview/datastructure/TraversalBinaryTree$Node.class b/bin/com/duweri/interview/datastructure/TraversalBinaryTree$Node.class deleted file mode 100644 index f526e02..0000000 Binary files a/bin/com/duweri/interview/datastructure/TraversalBinaryTree$Node.class and /dev/null differ diff --git a/bin/com/duweri/interview/datastructure/TraversalBinaryTree.class b/bin/com/duweri/interview/datastructure/TraversalBinaryTree.class deleted file mode 100644 index 0ed1009..0000000 Binary files a/bin/com/duweri/interview/datastructure/TraversalBinaryTree.class and /dev/null differ diff --git a/bin/com/duweri/interview/string/StringTest.class b/bin/com/duweri/interview/string/StringTest.class deleted file mode 100644 index 0023bf7..0000000 Binary files a/bin/com/duweri/interview/string/StringTest.class and /dev/null differ diff --git a/bin/com/duweri/interview/string/Test1.class b/bin/com/duweri/interview/string/Test1.class deleted file mode 100644 index 4ef48e4..0000000 Binary files a/bin/com/duweri/interview/string/Test1.class and /dev/null differ diff --git a/bin/com/duweri/interview/string/Test2.class b/bin/com/duweri/interview/string/Test2.class deleted file mode 100644 index f6bf6b2..0000000 Binary files a/bin/com/duweri/interview/string/Test2.class and /dev/null differ diff --git a/bin/com/duweri/interview/string/Test3.class b/bin/com/duweri/interview/string/Test3.class deleted file mode 100644 index 05f9765..0000000 Binary files a/bin/com/duweri/interview/string/Test3.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/binarytree/BinaryNode.class b/bin/com/github/pedrovgs/binarytree/BinaryNode.class deleted file mode 100644 index b4dc15d..0000000 Binary files a/bin/com/github/pedrovgs/binarytree/BinaryNode.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/linkedlist/ListNode.class b/bin/com/github/pedrovgs/linkedlist/ListNode.class deleted file mode 100644 index 176e8dc..0000000 Binary files a/bin/com/github/pedrovgs/linkedlist/ListNode.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/pair/Pair.class b/bin/com/github/pedrovgs/pair/Pair.class deleted file mode 100644 index daeb1a2..0000000 Binary files a/bin/com/github/pedrovgs/pair/Pair.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem1/BitsCounter.class b/bin/com/github/pedrovgs/problem1/BitsCounter.class deleted file mode 100644 index 9aab4b7..0000000 Binary files a/bin/com/github/pedrovgs/problem1/BitsCounter.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem10/RemoveDuplicates.class b/bin/com/github/pedrovgs/problem10/RemoveDuplicates.class deleted file mode 100644 index 74de42b..0000000 Binary files a/bin/com/github/pedrovgs/problem10/RemoveDuplicates.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem11/IntToString.class b/bin/com/github/pedrovgs/problem11/IntToString.class deleted file mode 100644 index 8a46ed3..0000000 Binary files a/bin/com/github/pedrovgs/problem11/IntToString.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem12/MoveZerosInArray.class b/bin/com/github/pedrovgs/problem12/MoveZerosInArray.class deleted file mode 100644 index 4cacf88..0000000 Binary files a/bin/com/github/pedrovgs/problem12/MoveZerosInArray.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem13/BinaryTreeByLevel.class b/bin/com/github/pedrovgs/problem13/BinaryTreeByLevel.class deleted file mode 100644 index 9ea4988..0000000 Binary files a/bin/com/github/pedrovgs/problem13/BinaryTreeByLevel.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem14/BinaryTreePreOrder.class b/bin/com/github/pedrovgs/problem14/BinaryTreePreOrder.class deleted file mode 100644 index 74f9138..0000000 Binary files a/bin/com/github/pedrovgs/problem14/BinaryTreePreOrder.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem15/BinaryTreeInOrder.class b/bin/com/github/pedrovgs/problem15/BinaryTreeInOrder.class deleted file mode 100644 index 6eae4fc..0000000 Binary files a/bin/com/github/pedrovgs/problem15/BinaryTreeInOrder.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem16/BinaryTreePostOrder.class b/bin/com/github/pedrovgs/problem16/BinaryTreePostOrder.class deleted file mode 100644 index bc11758..0000000 Binary files a/bin/com/github/pedrovgs/problem16/BinaryTreePostOrder.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem17/BinaryTreeEquals.class b/bin/com/github/pedrovgs/problem17/BinaryTreeEquals.class deleted file mode 100644 index 85f8356..0000000 Binary files a/bin/com/github/pedrovgs/problem17/BinaryTreeEquals.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem18/IsBST.class b/bin/com/github/pedrovgs/problem18/IsBST.class deleted file mode 100644 index 7a85290..0000000 Binary files a/bin/com/github/pedrovgs/problem18/IsBST.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem19/BinaryTreeDepth.class b/bin/com/github/pedrovgs/problem19/BinaryTreeDepth.class deleted file mode 100644 index 606087e..0000000 Binary files a/bin/com/github/pedrovgs/problem19/BinaryTreeDepth.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem2/Vector.class b/bin/com/github/pedrovgs/problem2/Vector.class deleted file mode 100644 index 48fe780..0000000 Binary files a/bin/com/github/pedrovgs/problem2/Vector.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem2/VectorScalarProduct.class b/bin/com/github/pedrovgs/problem2/VectorScalarProduct.class deleted file mode 100644 index 1de778b..0000000 Binary files a/bin/com/github/pedrovgs/problem2/VectorScalarProduct.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem20/MultiplicationWithoutMultiply.class b/bin/com/github/pedrovgs/problem20/MultiplicationWithoutMultiply.class deleted file mode 100644 index 97e60e8..0000000 Binary files a/bin/com/github/pedrovgs/problem20/MultiplicationWithoutMultiply.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem21/LowestCommonAncestor.class b/bin/com/github/pedrovgs/problem21/LowestCommonAncestor.class deleted file mode 100644 index 98b41e9..0000000 Binary files a/bin/com/github/pedrovgs/problem21/LowestCommonAncestor.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem22/ReverseLinkedList.class b/bin/com/github/pedrovgs/problem22/ReverseLinkedList.class deleted file mode 100644 index 9546a9d..0000000 Binary files a/bin/com/github/pedrovgs/problem22/ReverseLinkedList.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem23/FakeFile.class b/bin/com/github/pedrovgs/problem23/FakeFile.class deleted file mode 100644 index 05513bf..0000000 Binary files a/bin/com/github/pedrovgs/problem23/FakeFile.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem23/RemoveComments.class b/bin/com/github/pedrovgs/problem23/RemoveComments.class deleted file mode 100644 index deeb68d..0000000 Binary files a/bin/com/github/pedrovgs/problem23/RemoveComments.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem24/SortedArrayToBST.class b/bin/com/github/pedrovgs/problem24/SortedArrayToBST.class deleted file mode 100644 index c00469e..0000000 Binary files a/bin/com/github/pedrovgs/problem24/SortedArrayToBST.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem25/Anagrams.class b/bin/com/github/pedrovgs/problem25/Anagrams.class deleted file mode 100644 index 294c97c..0000000 Binary files a/bin/com/github/pedrovgs/problem25/Anagrams.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem26/Palindromes.class b/bin/com/github/pedrovgs/problem26/Palindromes.class deleted file mode 100644 index 3bda7e5..0000000 Binary files a/bin/com/github/pedrovgs/problem26/Palindromes.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem27/ReverseSentence.class b/bin/com/github/pedrovgs/problem27/ReverseSentence.class deleted file mode 100644 index 21f3a8e..0000000 Binary files a/bin/com/github/pedrovgs/problem27/ReverseSentence.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem28/FindSums.class b/bin/com/github/pedrovgs/problem28/FindSums.class deleted file mode 100644 index 7a62d46..0000000 Binary files a/bin/com/github/pedrovgs/problem28/FindSums.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem29/AreAnagrams.class b/bin/com/github/pedrovgs/problem29/AreAnagrams.class deleted file mode 100644 index 5adcbf0..0000000 Binary files a/bin/com/github/pedrovgs/problem29/AreAnagrams.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem3/SumBinaryNumbers.class b/bin/com/github/pedrovgs/problem3/SumBinaryNumbers.class deleted file mode 100644 index b879a23..0000000 Binary files a/bin/com/github/pedrovgs/problem3/SumBinaryNumbers.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem30/ScientificNotation.class b/bin/com/github/pedrovgs/problem30/ScientificNotation.class deleted file mode 100644 index 8687564..0000000 Binary files a/bin/com/github/pedrovgs/problem30/ScientificNotation.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem31/FindLongestConsecutiveSequence.class b/bin/com/github/pedrovgs/problem31/FindLongestConsecutiveSequence.class deleted file mode 100644 index 85283ad..0000000 Binary files a/bin/com/github/pedrovgs/problem31/FindLongestConsecutiveSequence.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem32/Contains.class b/bin/com/github/pedrovgs/problem32/Contains.class deleted file mode 100644 index 2cc16f7..0000000 Binary files a/bin/com/github/pedrovgs/problem32/Contains.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem33/SimpleRegularExpression.class b/bin/com/github/pedrovgs/problem33/SimpleRegularExpression.class deleted file mode 100644 index 357d5b0..0000000 Binary files a/bin/com/github/pedrovgs/problem33/SimpleRegularExpression.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem34/DotRegularExpression.class b/bin/com/github/pedrovgs/problem34/DotRegularExpression.class deleted file mode 100644 index 8cd9b24..0000000 Binary files a/bin/com/github/pedrovgs/problem34/DotRegularExpression.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem35/AsteriskRegularExpression.class b/bin/com/github/pedrovgs/problem35/AsteriskRegularExpression.class deleted file mode 100644 index ca1f829..0000000 Binary files a/bin/com/github/pedrovgs/problem35/AsteriskRegularExpression.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem36/AvlTreeMedian.class b/bin/com/github/pedrovgs/problem36/AvlTreeMedian.class deleted file mode 100644 index 02eb2f1..0000000 Binary files a/bin/com/github/pedrovgs/problem36/AvlTreeMedian.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem37/PathCalculator.class b/bin/com/github/pedrovgs/problem37/PathCalculator.class deleted file mode 100644 index 9c1054c..0000000 Binary files a/bin/com/github/pedrovgs/problem37/PathCalculator.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem38/PathToEveryLeaf.class b/bin/com/github/pedrovgs/problem38/PathToEveryLeaf.class deleted file mode 100644 index d6aaee6..0000000 Binary files a/bin/com/github/pedrovgs/problem38/PathToEveryLeaf.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem39/MultiplyArrayElements.class b/bin/com/github/pedrovgs/problem39/MultiplyArrayElements.class deleted file mode 100644 index d046d37..0000000 Binary files a/bin/com/github/pedrovgs/problem39/MultiplyArrayElements.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem4/SquareRoot.class b/bin/com/github/pedrovgs/problem4/SquareRoot.class deleted file mode 100644 index eae4ba6..0000000 Binary files a/bin/com/github/pedrovgs/problem4/SquareRoot.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem40/MoveElementsToPositions.class b/bin/com/github/pedrovgs/problem40/MoveElementsToPositions.class deleted file mode 100644 index 87d759a..0000000 Binary files a/bin/com/github/pedrovgs/problem40/MoveElementsToPositions.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem41/GoThroughMatrixInSpiral.class b/bin/com/github/pedrovgs/problem41/GoThroughMatrixInSpiral.class deleted file mode 100644 index 356139e..0000000 Binary files a/bin/com/github/pedrovgs/problem41/GoThroughMatrixInSpiral.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem42/FloodFill.class b/bin/com/github/pedrovgs/problem42/FloodFill.class deleted file mode 100644 index 2add8d9..0000000 Binary files a/bin/com/github/pedrovgs/problem42/FloodFill.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem43/CombinationOfIntegers.class b/bin/com/github/pedrovgs/problem43/CombinationOfIntegers.class deleted file mode 100644 index ea9a217..0000000 Binary files a/bin/com/github/pedrovgs/problem43/CombinationOfIntegers.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem44/FindMinNumberAtPosition.class b/bin/com/github/pedrovgs/problem44/FindMinNumberAtPosition.class deleted file mode 100644 index d2e4fed..0000000 Binary files a/bin/com/github/pedrovgs/problem44/FindMinNumberAtPosition.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem45/FindNthMostRepeatedElement.class b/bin/com/github/pedrovgs/problem45/FindNthMostRepeatedElement.class deleted file mode 100644 index 8084f2d..0000000 Binary files a/bin/com/github/pedrovgs/problem45/FindNthMostRepeatedElement.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem46/BinaryTreeSerialization.class b/bin/com/github/pedrovgs/problem46/BinaryTreeSerialization.class deleted file mode 100644 index e886bae..0000000 Binary files a/bin/com/github/pedrovgs/problem46/BinaryTreeSerialization.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem47/ReturnChange.class b/bin/com/github/pedrovgs/problem47/ReturnChange.class deleted file mode 100644 index 9ac5453..0000000 Binary files a/bin/com/github/pedrovgs/problem47/ReturnChange.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem48/WordSearch.class b/bin/com/github/pedrovgs/problem48/WordSearch.class deleted file mode 100644 index 5bd4ac2..0000000 Binary files a/bin/com/github/pedrovgs/problem48/WordSearch.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem49/CombinationsOfChange.class b/bin/com/github/pedrovgs/problem49/CombinationsOfChange.class deleted file mode 100644 index e8a3e68..0000000 Binary files a/bin/com/github/pedrovgs/problem49/CombinationsOfChange.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem5/DivideUsingSubtraction.class b/bin/com/github/pedrovgs/problem5/DivideUsingSubtraction.class deleted file mode 100644 index 722fcba..0000000 Binary files a/bin/com/github/pedrovgs/problem5/DivideUsingSubtraction.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem50/UniqueChars.class b/bin/com/github/pedrovgs/problem50/UniqueChars.class deleted file mode 100644 index 88cb7eb..0000000 Binary files a/bin/com/github/pedrovgs/problem50/UniqueChars.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem51/ReverseString.class b/bin/com/github/pedrovgs/problem51/ReverseString.class deleted file mode 100644 index c35a88f..0000000 Binary files a/bin/com/github/pedrovgs/problem51/ReverseString.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem52/ReplaceSpaces.class b/bin/com/github/pedrovgs/problem52/ReplaceSpaces.class deleted file mode 100644 index 2bc9240..0000000 Binary files a/bin/com/github/pedrovgs/problem52/ReplaceSpaces.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem53/CompressString.class b/bin/com/github/pedrovgs/problem53/CompressString.class deleted file mode 100644 index d54b206..0000000 Binary files a/bin/com/github/pedrovgs/problem53/CompressString.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem54/RotateMatrix.class b/bin/com/github/pedrovgs/problem54/RotateMatrix.class deleted file mode 100644 index 912b5b3..0000000 Binary files a/bin/com/github/pedrovgs/problem54/RotateMatrix.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem55/RewriteRowAndColumnsWithZeros.class b/bin/com/github/pedrovgs/problem55/RewriteRowAndColumnsWithZeros.class deleted file mode 100644 index a370909..0000000 Binary files a/bin/com/github/pedrovgs/problem55/RewriteRowAndColumnsWithZeros.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem56/IsRotationUsingIsSubstring.class b/bin/com/github/pedrovgs/problem56/IsRotationUsingIsSubstring.class deleted file mode 100644 index dbb79b3..0000000 Binary files a/bin/com/github/pedrovgs/problem56/IsRotationUsingIsSubstring.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem57/RemoveListDuplicatedElements.class b/bin/com/github/pedrovgs/problem57/RemoveListDuplicatedElements.class deleted file mode 100644 index 757140d..0000000 Binary files a/bin/com/github/pedrovgs/problem57/RemoveListDuplicatedElements.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem58/FindKthElement.class b/bin/com/github/pedrovgs/problem58/FindKthElement.class deleted file mode 100644 index a9e816f..0000000 Binary files a/bin/com/github/pedrovgs/problem58/FindKthElement.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem59/DeleteListNode.class b/bin/com/github/pedrovgs/problem59/DeleteListNode.class deleted file mode 100644 index 86c1d39..0000000 Binary files a/bin/com/github/pedrovgs/problem59/DeleteListNode.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem6/MergeSortedArrays.class b/bin/com/github/pedrovgs/problem6/MergeSortedArrays.class deleted file mode 100644 index 41b3fa9..0000000 Binary files a/bin/com/github/pedrovgs/problem6/MergeSortedArrays.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem60/PartitionList.class b/bin/com/github/pedrovgs/problem60/PartitionList.class deleted file mode 100644 index e622f5e..0000000 Binary files a/bin/com/github/pedrovgs/problem60/PartitionList.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem61/SumLists.class b/bin/com/github/pedrovgs/problem61/SumLists.class deleted file mode 100644 index 5bf81b3..0000000 Binary files a/bin/com/github/pedrovgs/problem61/SumLists.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem62/PalindromeList.class b/bin/com/github/pedrovgs/problem62/PalindromeList.class deleted file mode 100644 index 7f7f168..0000000 Binary files a/bin/com/github/pedrovgs/problem62/PalindromeList.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem63/ConstantComplexityOrderStack$MinValue.class b/bin/com/github/pedrovgs/problem63/ConstantComplexityOrderStack$MinValue.class deleted file mode 100644 index f8f7e3e..0000000 Binary files a/bin/com/github/pedrovgs/problem63/ConstantComplexityOrderStack$MinValue.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem63/ConstantComplexityOrderStack$Stack1.class b/bin/com/github/pedrovgs/problem63/ConstantComplexityOrderStack$Stack1.class deleted file mode 100644 index dbda8dd..0000000 Binary files a/bin/com/github/pedrovgs/problem63/ConstantComplexityOrderStack$Stack1.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem63/ConstantComplexityOrderStack$Stack2.class b/bin/com/github/pedrovgs/problem63/ConstantComplexityOrderStack$Stack2.class deleted file mode 100644 index 11917c5..0000000 Binary files a/bin/com/github/pedrovgs/problem63/ConstantComplexityOrderStack$Stack2.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem63/ConstantComplexityOrderStack.class b/bin/com/github/pedrovgs/problem63/ConstantComplexityOrderStack.class deleted file mode 100644 index 77c7d93..0000000 Binary files a/bin/com/github/pedrovgs/problem63/ConstantComplexityOrderStack.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem64/GetTheElementInTheMiddleOfTheList.class b/bin/com/github/pedrovgs/problem64/GetTheElementInTheMiddleOfTheList.class deleted file mode 100644 index 89212e2..0000000 Binary files a/bin/com/github/pedrovgs/problem64/GetTheElementInTheMiddleOfTheList.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem65/IsTreeBalanced.class b/bin/com/github/pedrovgs/problem65/IsTreeBalanced.class deleted file mode 100644 index 2d6a8a3..0000000 Binary files a/bin/com/github/pedrovgs/problem65/IsTreeBalanced.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem66/TreeToListByLevel.class b/bin/com/github/pedrovgs/problem66/TreeToListByLevel.class deleted file mode 100644 index 890fa3c..0000000 Binary files a/bin/com/github/pedrovgs/problem66/TreeToListByLevel.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem67/MergeBinaryNumbers.class b/bin/com/github/pedrovgs/problem67/MergeBinaryNumbers.class deleted file mode 100644 index 188c42e..0000000 Binary files a/bin/com/github/pedrovgs/problem67/MergeBinaryNumbers.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem68/IsEven.class b/bin/com/github/pedrovgs/problem68/IsEven.class deleted file mode 100644 index d1da359..0000000 Binary files a/bin/com/github/pedrovgs/problem68/IsEven.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem69/BitsToTransform.class b/bin/com/github/pedrovgs/problem69/BitsToTransform.class deleted file mode 100644 index 182de93..0000000 Binary files a/bin/com/github/pedrovgs/problem69/BitsToTransform.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem7/FibonacciNumbers.class b/bin/com/github/pedrovgs/problem7/FibonacciNumbers.class deleted file mode 100644 index de5045e..0000000 Binary files a/bin/com/github/pedrovgs/problem7/FibonacciNumbers.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem70/ReverseOrderOfBinaryNumber.class b/bin/com/github/pedrovgs/problem70/ReverseOrderOfBinaryNumber.class deleted file mode 100644 index 37b7f3d..0000000 Binary files a/bin/com/github/pedrovgs/problem70/ReverseOrderOfBinaryNumber.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem71/ReverseBinaryNumber.class b/bin/com/github/pedrovgs/problem71/ReverseBinaryNumber.class deleted file mode 100644 index 97eb68e..0000000 Binary files a/bin/com/github/pedrovgs/problem71/ReverseBinaryNumber.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem72/FindTheMissingNumber.class b/bin/com/github/pedrovgs/problem72/FindTheMissingNumber.class deleted file mode 100644 index 7d2a498..0000000 Binary files a/bin/com/github/pedrovgs/problem72/FindTheMissingNumber.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem73/SubtractAdding.class b/bin/com/github/pedrovgs/problem73/SubtractAdding.class deleted file mode 100644 index 831649e..0000000 Binary files a/bin/com/github/pedrovgs/problem73/SubtractAdding.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem74/BubbleSort.class b/bin/com/github/pedrovgs/problem74/BubbleSort.class deleted file mode 100644 index cef4d83..0000000 Binary files a/bin/com/github/pedrovgs/problem74/BubbleSort.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem75/SelectionSort.class b/bin/com/github/pedrovgs/problem75/SelectionSort.class deleted file mode 100644 index ff177c0..0000000 Binary files a/bin/com/github/pedrovgs/problem75/SelectionSort.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem76/InsertionSort.class b/bin/com/github/pedrovgs/problem76/InsertionSort.class deleted file mode 100644 index 5649ab3..0000000 Binary files a/bin/com/github/pedrovgs/problem76/InsertionSort.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem77/HelloWorldWithoutSemicolon.class b/bin/com/github/pedrovgs/problem77/HelloWorldWithoutSemicolon.class deleted file mode 100644 index 78fdf20..0000000 Binary files a/bin/com/github/pedrovgs/problem77/HelloWorldWithoutSemicolon.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem78/AutoBoxingTrick.class b/bin/com/github/pedrovgs/problem78/AutoBoxingTrick.class deleted file mode 100644 index 9995279..0000000 Binary files a/bin/com/github/pedrovgs/problem78/AutoBoxingTrick.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem79/MergeSort.class b/bin/com/github/pedrovgs/problem79/MergeSort.class deleted file mode 100644 index c7dacc9..0000000 Binary files a/bin/com/github/pedrovgs/problem79/MergeSort.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem8/SplitArray.class b/bin/com/github/pedrovgs/problem8/SplitArray.class deleted file mode 100644 index 1422015..0000000 Binary files a/bin/com/github/pedrovgs/problem8/SplitArray.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/problem9/Factorial.class b/bin/com/github/pedrovgs/problem9/Factorial.class deleted file mode 100644 index e7020a7..0000000 Binary files a/bin/com/github/pedrovgs/problem9/Factorial.class and /dev/null differ diff --git a/bin/com/github/pedrovgs/sortingalgorithm/SortingAlgorithm.class b/bin/com/github/pedrovgs/sortingalgorithm/SortingAlgorithm.class deleted file mode 100644 index 42954a9..0000000 Binary files a/bin/com/github/pedrovgs/sortingalgorithm/SortingAlgorithm.class and /dev/null differ diff --git a/bin/com/offer/JumpStep.class b/bin/com/offer/JumpStep.class deleted file mode 100644 index 448f11f..0000000 Binary files a/bin/com/offer/JumpStep.class and /dev/null differ diff --git a/bin/com/offer/MinTotalInArr$1.class b/bin/com/offer/MinTotalInArr$1.class deleted file mode 100644 index 4d4c1dd..0000000 Binary files a/bin/com/offer/MinTotalInArr$1.class and /dev/null differ diff --git a/bin/com/offer/MinTotalInArr.class b/bin/com/offer/MinTotalInArr.class deleted file mode 100644 index a3a8e4c..0000000 Binary files a/bin/com/offer/MinTotalInArr.class and /dev/null differ diff --git a/bin/com/sogou/HelloSogou$1.class b/bin/com/sogou/HelloSogou$1.class deleted file mode 100644 index c6d1da9..0000000 Binary files a/bin/com/sogou/HelloSogou$1.class and /dev/null differ diff --git a/bin/com/sogou/HelloSogou.class b/bin/com/sogou/HelloSogou.class deleted file mode 100644 index 11ec85a..0000000 Binary files a/bin/com/sogou/HelloSogou.class and /dev/null differ diff --git a/bin/com/sohu/Test1.class b/bin/com/sohu/Test1.class deleted file mode 100644 index 139134c..0000000 Binary files a/bin/com/sohu/Test1.class and /dev/null differ diff --git a/bin/com/sohu/Test2.class b/bin/com/sohu/Test2.class deleted file mode 100644 index f383e45..0000000 Binary files a/bin/com/sohu/Test2.class and /dev/null differ diff --git a/bin/com/toutiao/HuiWenDecode.class b/bin/com/toutiao/HuiWenDecode.class deleted file mode 100644 index b86ee94..0000000 Binary files a/bin/com/toutiao/HuiWenDecode.class and /dev/null differ diff --git a/bin/com/toutiao/Test.class b/bin/com/toutiao/Test.class deleted file mode 100644 index d16b178..0000000 Binary files a/bin/com/toutiao/Test.class and /dev/null differ diff --git a/bin/com/toutiao/ZhuanJi.class b/bin/com/toutiao/ZhuanJi.class deleted file mode 100644 index eb69fe0..0000000 Binary files a/bin/com/toutiao/ZhuanJi.class and /dev/null differ diff --git a/bin/com/wangyi/Test01.class b/bin/com/wangyi/Test01.class deleted file mode 100644 index 3f6ad2e..0000000 Binary files a/bin/com/wangyi/Test01.class and /dev/null differ diff --git a/bin/com/wangyi/Test02.class b/bin/com/wangyi/Test02.class deleted file mode 100644 index a63b4d5..0000000 Binary files a/bin/com/wangyi/Test02.class and /dev/null differ diff --git a/bin/com/wangyi/Test03.class b/bin/com/wangyi/Test03.class deleted file mode 100644 index b42774d..0000000 Binary files a/bin/com/wangyi/Test03.class and /dev/null differ diff --git a/bin/com/wangyi/Test04.class b/bin/com/wangyi/Test04.class deleted file mode 100644 index 9c59bbf..0000000 Binary files a/bin/com/wangyi/Test04.class and /dev/null differ diff --git a/bin/com/xiaomi/PhoneNum.class b/bin/com/xiaomi/PhoneNum.class deleted file mode 100644 index e231f72..0000000 Binary files a/bin/com/xiaomi/PhoneNum.class and /dev/null differ diff --git a/bin/com/xiaomi/ReversString.class b/bin/com/xiaomi/ReversString.class deleted file mode 100644 index 3796eef..0000000 Binary files a/bin/com/xiaomi/ReversString.class and /dev/null differ diff --git a/bin/com/youku/A.class b/bin/com/youku/A.class deleted file mode 100644 index 443a579..0000000 Binary files a/bin/com/youku/A.class and /dev/null differ diff --git a/bin/com/youku/HelloA.class b/bin/com/youku/HelloA.class deleted file mode 100644 index 82eda82..0000000 Binary files a/bin/com/youku/HelloA.class and /dev/null differ diff --git a/bin/com/youku/JAVA_01.class b/bin/com/youku/JAVA_01.class deleted file mode 100644 index 6c726b5..0000000 Binary files a/bin/com/youku/JAVA_01.class and /dev/null differ diff --git a/bin/com/youku/JAVA_02.class b/bin/com/youku/JAVA_02.class deleted file mode 100644 index d477c59..0000000 Binary files a/bin/com/youku/JAVA_02.class and /dev/null differ diff --git a/bin/com/youku/JAVA_03.class b/bin/com/youku/JAVA_03.class deleted file mode 100644 index ac0d985..0000000 Binary files a/bin/com/youku/JAVA_03.class and /dev/null differ diff --git a/bin/com/youku/JAVA_04.class b/bin/com/youku/JAVA_04.class deleted file mode 100644 index f17e0dc..0000000 Binary files a/bin/com/youku/JAVA_04.class and /dev/null differ diff --git a/bin/com/youku/JAVA_05$InterClass.class b/bin/com/youku/JAVA_05$InterClass.class deleted file mode 100644 index 3ce6a9d..0000000 Binary files a/bin/com/youku/JAVA_05$InterClass.class and /dev/null differ diff --git a/bin/com/youku/JAVA_05.class b/bin/com/youku/JAVA_05.class deleted file mode 100644 index b622107..0000000 Binary files a/bin/com/youku/JAVA_05.class and /dev/null differ diff --git a/bin/com/youku/JAVA_06.class b/bin/com/youku/JAVA_06.class deleted file mode 100644 index a8a4efb..0000000 Binary files a/bin/com/youku/JAVA_06.class and /dev/null differ diff --git a/bin/com/youku/X.class b/bin/com/youku/X.class deleted file mode 100644 index 71def2e..0000000 Binary files a/bin/com/youku/X.class and /dev/null differ diff --git a/bin/com/youku/Y.class b/bin/com/youku/Y.class deleted file mode 100644 index 97adaae..0000000 Binary files a/bin/com/youku/Y.class and /dev/null differ diff --git a/bin/comparable/MyComparable.class b/bin/comparable/MyComparable.class deleted file mode 100644 index 56cf50f..0000000 Binary files a/bin/comparable/MyComparable.class and /dev/null differ diff --git a/bin/comparable/Person.class b/bin/comparable/Person.class deleted file mode 100644 index 7c6415c..0000000 Binary files a/bin/comparable/Person.class and /dev/null differ diff --git a/bin/comparable/TestComparable.class b/bin/comparable/TestComparable.class deleted file mode 100644 index fd50c61..0000000 Binary files a/bin/comparable/TestComparable.class and /dev/null differ diff --git a/bin/comparable/TestComparator.class b/bin/comparable/TestComparator.class deleted file mode 100644 index 78354f1..0000000 Binary files a/bin/comparable/TestComparator.class and /dev/null differ diff --git a/src/com/alibaba/Banker.java b/src/com/alibaba/Banker.java index f1ae41e..0800c9f 100644 --- a/src/com/alibaba/Banker.java +++ b/src/com/alibaba/Banker.java @@ -3,145 +3,144 @@ import java.util.Scanner; -public class Banker{ - int available[] = new int[]{3,3,2};//可得到的资源 - int max[][] = new int[][]{{7,5,3},{3,2,2},{9,0,2},{2,2,2},{4,3,3}};//每个进程最大资源数 - int allocation[][] = new int[][]{{0,1,0},{2,0,0},{3,0,2},{2,1,1},{0,0,2}};//每个进程目前拥有的资源数 - int need[][] = new int[][]{{7,4,3},{1,2,2},{6,0,0},{0,1,1},{4,3,1}};//每个进程需要的资源数 - - void showData()//展示数据输出每个进程的相关数据 - { - System.out.println("进程号 Max Allocation Need "); - System.out.println(" A B C A B C A B C"); - for(int i = 0;i<5;i++) - { - System.out.print(i+" "); - for(int m = 0;m<3;m++) System.out.print(max[i][m]+" "); - for(int m = 0;m<3;m++) System.out.print(allocation[i][m]+" "); - for(int m = 0;m<3;m++) System.out.print(need[i][m]+" "); - System.out.println(); - } - } - - boolean change(int inRequestNum,int inRequest[]){//分配数据 - int requestNum = inRequestNum; - int request[] = inRequest; - // for(int i=0;i<3;i++)System.out.println("修改前available"+available[i]); - if(!(request[0]<=need[requestNum][0]&&request[1]<=need[requestNum][1]&&request[2]<=need[requestNum][2])){ - System.out.println("请求的资源数超过了所需要的最大值,分配错误"); - return false; - } - if((request[0]<=available[0]&&request[1]<=available[1]&&request[2]<=available[2])==false){ - System.out.println("尚无足够资源分配,必须等待"); - return false; - } - for(int i = 0;i<3;i++){//试分配数据给请求的线程 - - available[i] = available[i]-request[i]; - - allocation[requestNum][i] = allocation[requestNum][i] + request[i]; - - need[requestNum][i] = need[requestNum][i] - request[i]; - - } - boolean flag = checkSafe(available[0],available[1],available[2]);//进行安全性检查并返回是否安全 - - if(flag==true){ - System.out.println("能够安全分配"); - return true; - }else{ - System.out.println("不能够安全分配"); - for(int i = 0;i<3;i++){ - available[i] = available[i]+request[i]; - allocation[requestNum][i] = allocation[requestNum][i] - request[i]; - need[requestNum][i] = need[requestNum][i] + request[i]; - } - return false; - } - - } - - boolean checkSafe(int a,int b,int c){ - int work[] = new int[3]; - work[0] = a; - work[1] = b; - work[2] = c; - int i=0; - boolean finish[] = new boolean[5]; - while(i<5)//寻找一个能够满足的认为完成后才去执行下一进程 - { - if(finish[i]==false&&need[i][0]<=work[0]&&need[i][1]<=work[1]&&need[i][2]<=work[2]){//找到满足的修改work值,然后i=0,重新从开始的为分配的中寻找 - System.out.println("分配成功的是"+i); - for(int m = 0;m<3;m++) - work[m] =work[m] + allocation[i][m]; - finish[i] = true; - i=0; - }else//如果没有找到直接i++ - i++; - } - - for(i=0;i<5;i++){ - - if(finish[i]==false) - - return false; - - } - - return true; - - } - - public static void main(String[] args) - - { - - Banker bank = new Banker(); - - bank.showData(); - - int request[] =new int[3]; - - int requestNum; - - String source[] = new String[]{"A","B","C"}; - - Scanner s = new Scanner(System.in); - - String choice = new String(); - - while(true)//循环进行分配 - - { - - System.out.println("请输入要请求的进程号(0--4):"); - - requestNum = s.nextInt(); - - System.out.print("请输入请求的资源数目"); - - for(int i = 0;i<3;i++) - - { - - System.out.println(source[i]+"资源的数目:"); - - request[i] = s.nextInt(); - - } - - bank.change(requestNum, request); - - System.out.println("是否再请求分配(y/n)"); - - choice = s.next(); - - if(choice.equals("n")) - - break; - - } - - } - - } \ No newline at end of file +public class Banker { + int available[] = new int[]{3, 3, 2};//鍙緱鍒扮殑璧勬簮 + int max[][] = new int[][]{{7, 5, 3}, {3, 2, 2}, {9, 0, 2}, {2, 2, 2}, {4, 3, 3}};//姣忎釜杩涚▼鏈澶ц祫婧愭暟 + int allocation[][] = new int[][]{{0, 1, 0}, {2, 0, 0}, {3, 0, 2}, {2, 1, 1}, {0, 0, 2}};//姣忎釜杩涚▼鐩墠鎷ユ湁鐨勮祫婧愭暟 + int need[][] = new int[][]{{7, 4, 3}, {1, 2, 2}, {6, 0, 0}, {0, 1, 1}, {4, 3, 1}};//姣忎釜杩涚▼闇瑕佺殑璧勬簮鏁 + + void showData()//灞曠ず鏁版嵁杈撳嚭姣忎釜杩涚▼鐨勭浉鍏虫暟鎹 + { + System.out.println("杩涚▼鍙 Max Allocation Need "); + System.out.println(" A B C A B C A B C"); + for (int i = 0; i < 5; i++) { + System.out.print(i + " "); + for (int m = 0; m < 3; m++) System.out.print(max[i][m] + " "); + for (int m = 0; m < 3; m++) System.out.print(allocation[i][m] + " "); + for (int m = 0; m < 3; m++) System.out.print(need[i][m] + " "); + System.out.println(); + } + } + + boolean change(int inRequestNum, int inRequest[]) {//鍒嗛厤鏁版嵁 + int requestNum = inRequestNum; + int request[] = inRequest; + // for(int i=0;i<3;i++)System.out.println("淇敼鍓峚vailable"+available[i]); + if (!(request[0] <= need[requestNum][0] && request[1] <= need[requestNum][1] && request[2] <= need[requestNum][2])) { + System.out.println("璇锋眰鐨勮祫婧愭暟瓒呰繃浜嗘墍闇瑕佺殑鏈澶у硷紝鍒嗛厤閿欒"); + return false; + } + if ((request[0] <= available[0] && request[1] <= available[1] && request[2] <= available[2]) == false) { + System.out.println("灏氭棤瓒冲璧勬簮鍒嗛厤锛屽繀椤荤瓑寰"); + return false; + } + for (int i = 0; i < 3; i++) {//璇曞垎閰嶆暟鎹粰璇锋眰鐨勭嚎绋 + + available[i] = available[i] - request[i]; + + allocation[requestNum][i] = allocation[requestNum][i] + request[i]; + + need[requestNum][i] = need[requestNum][i] - request[i]; + + } + boolean flag = checkSafe(available[0], available[1], available[2]);//杩涜瀹夊叏鎬ф鏌ュ苟杩斿洖鏄惁瀹夊叏 + + if (flag == true) { + System.out.println("鑳藉瀹夊叏鍒嗛厤"); + return true; + } else { + System.out.println("涓嶈兘澶熷畨鍏ㄥ垎閰"); + for (int i = 0; i < 3; i++) { + available[i] = available[i] + request[i]; + allocation[requestNum][i] = allocation[requestNum][i] - request[i]; + need[requestNum][i] = need[requestNum][i] + request[i]; + } + return false; + } + + } + + boolean checkSafe(int a, int b, int c) { + int work[] = new int[3]; + work[0] = a; + work[1] = b; + work[2] = c; + int i = 0; + boolean finish[] = new boolean[5]; + while (i < 5)//瀵绘壘涓涓兘澶熸弧瓒崇殑璁や负瀹屾垚鍚庢墠鍘绘墽琛屼笅涓杩涚▼ + { + if (finish[i] == false && need[i][0] <= work[0] && need[i][1] <= work[1] && need[i][2] <= work[2]) {//鎵惧埌婊¤冻鐨勪慨鏀箇ork鍊硷紝鐒跺悗i=0锛岄噸鏂颁粠寮濮嬬殑涓哄垎閰嶇殑涓鎵 + System.out.println("鍒嗛厤鎴愬姛鐨勬槸" + i); + for (int m = 0; m < 3; m++) + work[m] = work[m] + allocation[i][m]; + finish[i] = true; + i = 0; + } else//濡傛灉娌℃湁鎵惧埌鐩存帴i++ + i++; + } + + for (i = 0; i < 5; i++) { + + if (finish[i] == false) + + return false; + + } + + return true; + + } + + public static void main(String[] args) + + { + + Banker bank = new Banker(); + + bank.showData(); + + int request[] = new int[3]; + + int requestNum; + + String source[] = new String[]{"A", "B", "C"}; + + Scanner s = new Scanner(System.in); + + String choice = new String(); + + while (true)//寰幆杩涜鍒嗛厤 + + { + + System.out.println("璇疯緭鍏ヨ璇锋眰鐨勮繘绋嬪彿锛0--4锛夛細"); + + requestNum = s.nextInt(); + + System.out.print("璇疯緭鍏ヨ姹傜殑璧勬簮鏁扮洰"); + + for (int i = 0; i < 3; i++) + + { + + System.out.println(source[i] + "璧勬簮鐨勬暟鐩細"); + + request[i] = s.nextInt(); + + } + + bank.change(requestNum, request); + + System.out.println("鏄惁鍐嶈姹傚垎閰(y/n)"); + + choice = s.next(); + + if (choice.equals("n")) + + break; + + } + + } + +} \ No newline at end of file diff --git a/src/com/alibaba/Test_2.java b/src/com/alibaba/Test_2.java index 1dfc77b..148d24e 100644 --- a/src/com/alibaba/Test_2.java +++ b/src/com/alibaba/Test_2.java @@ -7,12 +7,12 @@ public static void main(String[] args){ Integer j = new Integer(3000); System.out.println(i == j); - //自动拆箱 + //鑷姩鎷嗙 System.out.println(j.equals(i)); - //自动装箱 - //Integer的equals方法比较的是值不是地址 - //String,Integer,Date在这些类当中equals有其自身的实现,而不再是比较类在堆内存中的存放地址了。 + //鑷姩瑁呯 + //Integer鐨別quals鏂规硶姣旇緝鐨勬槸鍊间笉鏄湴鍧 + //String,Integer,Date鍦ㄨ繖浜涚被褰撲腑equals鏈夊叾鑷韩鐨勫疄鐜帮紝鑰屼笉鍐嶆槸姣旇緝绫诲湪鍫嗗唴瀛樹腑鐨勫瓨鏀惧湴鍧浜嗐 } } diff --git a/src/com/baidu/PrintAB.java b/src/com/baidu/PrintAB.java index 7156699..e7a3912 100644 --- a/src/com/baidu/PrintAB.java +++ b/src/com/baidu/PrintAB.java @@ -6,7 +6,7 @@ public static void main(String[] args) { } /** - * 这个解法自己想的有点弱智了! + * 杩欎釜瑙f硶鑷繁鎯崇殑鏈夌偣寮辨櫤浜嗭紒 */ // public void printAB(){ // if(new PrintAB(){ @@ -22,7 +22,7 @@ public static void main(String[] args) { // } /** - * 借鉴的解法 + * 鍊熼壌鐨勮В娉 */ public void printAB(){ if(System.out.append("a")==null){ diff --git a/src/com/duwei/annotation/Define.java b/src/com/duwei/annotation/Define.java new file mode 100644 index 0000000..e293aa1 --- /dev/null +++ b/src/com/duwei/annotation/Define.java @@ -0,0 +1,16 @@ +package com.duwei.annotation; + + +import java.lang.annotation.*; + +/** + * 瀹氫箟娉ㄨВ鐨勫叧閿瓧 + */ + +@Documented +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.METHOD) +public @interface Define { + + +} diff --git a/src/com/duwei/annotation/Processor.java b/src/com/duwei/annotation/Processor.java new file mode 100644 index 0000000..ecc2303 --- /dev/null +++ b/src/com/duwei/annotation/Processor.java @@ -0,0 +1,36 @@ +package com.duwei.annotation; + +import javax.annotation.processing.AbstractProcessor; +import javax.annotation.processing.RoundEnvironment; +import javax.annotation.processing.SupportedAnnotationTypes; +import javax.annotation.processing.SupportedSourceVersion; +import javax.lang.model.SourceVersion; +import javax.lang.model.element.TypeElement; +import java.util.Set; + +//@SupportedAnnotationTypes("娉ㄨВ鐨勫悕瀛") +//@SupportedSourceVersion(SourceVersion.RELEASE_6) +public class Processor extends AbstractProcessor { + + + //鍞竴闇瑕佸鍐欑殑鎶借薄鏂规硶 + @Override + public boolean process(Set annotations, RoundEnvironment roundEnv) { + return false; + } + + //浣跨敤涓婇潰鐨勬敞瑙d唬鏇匡紝鎺ㄨ崘涓嶇敤娉ㄨВ锛屽洜涓烘贩娣嗙殑闂 + @Override + public Set getSupportedAnnotationTypes() { + return super.getSupportedAnnotationTypes(); + } + + //浣跨敤涓婇潰鐨勬敞瑙d唬鏇匡紝鎺ㄨ崘涓嶇敤娉ㄨВ锛屽洜涓烘贩娣嗙殑闂 + @Override + public SourceVersion getSupportedSourceVersion() { + return super.getSupportedSourceVersion(); + + } + + +} diff --git a/src/com/duwei/annotation/Usage.java b/src/com/duwei/annotation/Usage.java new file mode 100644 index 0000000..d5a1308 --- /dev/null +++ b/src/com/duwei/annotation/Usage.java @@ -0,0 +1,16 @@ +package com.duwei.annotation; + + +/** + * 娉ㄨВ鐨勪娇鐢 + * + * 瀹炵幇浜嗚嚜宸辩殑娉ㄨВ澶勭悊鍣紝闇瑕佸鍏惰繘琛屾敞鍐岋細 + * + * 寤虹珛锛歳esources/META-INFO/service/javax.annotation.processing.Processor鏂囦欢 + * 鍦ㄩ噷闈㈠啓涓婃垜浠敞瑙e鐞嗗櫒鐨勫畬鏁磋矾寰 + * + * 鎴栬咃紝浣跨敤google鐨刟utoService锛岃寰楀姞渚濊禆 + * + */ +public class Usage { +} diff --git a/src/com/duwei/classloading/ConstClass.java b/src/com/duwei/classloading/ConstClass.java index 21031ec..a2a88fe 100644 --- a/src/com/duwei/classloading/ConstClass.java +++ b/src/com/duwei/classloading/ConstClass.java @@ -2,8 +2,8 @@ public class ConstClass { static { - System.out.println("Const 被初始化了"); + System.out.println("Const 琚垵濮嬪寲浜"); } - //常量在编译阶段会调入类的常量池中,本质上并没有直接引用到定义常量的类中,因此不会触发定义常量的类的初始化 + //甯搁噺鍦ㄧ紪璇戦樁娈典細璋冨叆绫荤殑甯搁噺姹犱腑锛屾湰璐ㄤ笂骞舵病鏈夌洿鎺ュ紩鐢ㄥ埌瀹氫箟甯搁噺鐨勭被涓紝鍥犳涓嶄細瑙﹀彂瀹氫箟甯搁噺鐨勭被鐨勫垵濮嬪寲 public static final String HELLO_WORD = "hello word"; } diff --git a/src/com/duwei/classloading/SubClass.java b/src/com/duwei/classloading/SubClass.java index 58622d1..591e9d3 100644 --- a/src/com/duwei/classloading/SubClass.java +++ b/src/com/duwei/classloading/SubClass.java @@ -3,7 +3,7 @@ public class SubClass extends SuperClass { static { - System.out.println("SubClass 初始化了"); + System.out.println("SubClass 鍒濆鍖栦簡"); } } diff --git a/src/com/duwei/designpattern/absfactory/AbstractFactory.java b/src/com/duwei/designpattern/absfactory/AbstractFactory.java new file mode 100644 index 0000000..fc9b2db --- /dev/null +++ b/src/com/duwei/designpattern/absfactory/AbstractFactory.java @@ -0,0 +1,6 @@ +package com.duwei.designpattern.absfactory; + +public abstract class AbstractFactory { + public abstract Color getColor(String color); + public abstract Shape getShape(String shape); +} \ No newline at end of file diff --git a/src/com/duwei/designpattern/absfactory/AbstractFactoryPatternDemo.java b/src/com/duwei/designpattern/absfactory/AbstractFactoryPatternDemo.java new file mode 100644 index 0000000..bcb86ca --- /dev/null +++ b/src/com/duwei/designpattern/absfactory/AbstractFactoryPatternDemo.java @@ -0,0 +1,48 @@ +package com.duwei.designpattern.absfactory; + +public class AbstractFactoryPatternDemo { + public static void main(String[] args) { + + //鑾峰彇褰㈢姸宸ュ巶 + AbstractFactory shapeFactory = FactoryProducer.getFactory("SHAPE"); + + //鑾峰彇褰㈢姸涓 Circle 鐨勫璞 + Shape shape1 = shapeFactory.getShape("CIRCLE"); + + //璋冪敤 Circle 鐨 draw 鏂规硶 + shape1.draw(); + + //鑾峰彇褰㈢姸涓 Rectangle 鐨勫璞 + Shape shape2 = shapeFactory.getShape("RECTANGLE"); + + //璋冪敤 Rectangle 鐨 draw 鏂规硶 + shape2.draw(); + + //鑾峰彇褰㈢姸涓 Square 鐨勫璞 + Shape shape3 = shapeFactory.getShape("SQUARE"); + + //璋冪敤 Square 鐨 draw 鏂规硶 + shape3.draw(); + + //鑾峰彇棰滆壊宸ュ巶 + AbstractFactory colorFactory = FactoryProducer.getFactory("COLOR"); + + //鑾峰彇棰滆壊涓 Red 鐨勫璞 + Color color1 = colorFactory.getColor("RED"); + + //璋冪敤 Red 鐨 fill 鏂规硶 + color1.fill(); + + //鑾峰彇棰滆壊涓 Green 鐨勫璞 + Color color2 = colorFactory.getColor("Green"); + + //璋冪敤 Green 鐨 fill 鏂规硶 + color2.fill(); + + //鑾峰彇棰滆壊涓 Blue 鐨勫璞 + Color color3 = colorFactory.getColor("BLUE"); + + //璋冪敤 Blue 鐨 fill 鏂规硶 + color3.fill(); + } +} \ No newline at end of file diff --git a/src/com/duwei/designpattern/absfactory/Blue.java b/src/com/duwei/designpattern/absfactory/Blue.java new file mode 100644 index 0000000..abe9288 --- /dev/null +++ b/src/com/duwei/designpattern/absfactory/Blue.java @@ -0,0 +1,9 @@ +package com.duwei.designpattern.absfactory; + +public class Blue implements Color { + + @Override + public void fill() { + System.out.println("Inside Blue::fill() method."); + } +} \ No newline at end of file diff --git a/src/com/duwei/designpattern/absfactory/Circle.java b/src/com/duwei/designpattern/absfactory/Circle.java new file mode 100644 index 0000000..b00dc7e --- /dev/null +++ b/src/com/duwei/designpattern/absfactory/Circle.java @@ -0,0 +1,9 @@ +package com.duwei.designpattern.absfactory; + +public class Circle implements Shape { + + @Override + public void draw() { + System.out.println("Inside Circle::draw() method."); + } +} \ No newline at end of file diff --git a/src/com/duwei/designpattern/absfactory/Color.java b/src/com/duwei/designpattern/absfactory/Color.java new file mode 100644 index 0000000..8af5daa --- /dev/null +++ b/src/com/duwei/designpattern/absfactory/Color.java @@ -0,0 +1,5 @@ +package com.duwei.designpattern.absfactory; + +public interface Color { + void fill(); +} diff --git a/src/com/duwei/designpattern/absfactory/ColorFactory.java b/src/com/duwei/designpattern/absfactory/ColorFactory.java new file mode 100644 index 0000000..0fef92e --- /dev/null +++ b/src/com/duwei/designpattern/absfactory/ColorFactory.java @@ -0,0 +1,24 @@ +package com.duwei.designpattern.absfactory; + +public class ColorFactory extends AbstractFactory { + + @Override + public Shape getShape(String shapeType){ + return null; + } + + @Override + public Color getColor(String color) { + if(color == null){ + return null; + } + if(color.equalsIgnoreCase("RED")){ + return new Red(); + } else if(color.equalsIgnoreCase("GREEN")){ + return new Green(); + } else if(color.equalsIgnoreCase("BLUE")){ + return new Blue(); + } + return null; + } +} diff --git a/src/com/duwei/designpattern/absfactory/FactoryProducer.java b/src/com/duwei/designpattern/absfactory/FactoryProducer.java new file mode 100644 index 0000000..6853fc3 --- /dev/null +++ b/src/com/duwei/designpattern/absfactory/FactoryProducer.java @@ -0,0 +1,12 @@ +package com.duwei.designpattern.absfactory; + +public class FactoryProducer { + public static AbstractFactory getFactory(String choice){ + if(choice.equalsIgnoreCase("SHAPE")){ + return new ShapeFactory(); + } else if(choice.equalsIgnoreCase("COLOR")){ + return new ColorFactory(); + } + return null; + } +} \ No newline at end of file diff --git a/src/com/duwei/designpattern/absfactory/Green.java b/src/com/duwei/designpattern/absfactory/Green.java new file mode 100644 index 0000000..862d50c --- /dev/null +++ b/src/com/duwei/designpattern/absfactory/Green.java @@ -0,0 +1,9 @@ +package com.duwei.designpattern.absfactory; + +public class Green implements Color { + + @Override + public void fill() { + System.out.println("Inside Green::fill() method."); + } +} \ No newline at end of file diff --git a/src/com/duwei/designpattern/absfactory/Rectangle.java b/src/com/duwei/designpattern/absfactory/Rectangle.java new file mode 100644 index 0000000..b1b0c74 --- /dev/null +++ b/src/com/duwei/designpattern/absfactory/Rectangle.java @@ -0,0 +1,9 @@ +package com.duwei.designpattern.absfactory; + +public class Rectangle implements Shape { + + @Override + public void draw() { + System.out.println("Inside Rectangle::draw() method."); + } +} \ No newline at end of file diff --git a/src/com/duwei/designpattern/absfactory/Red.java b/src/com/duwei/designpattern/absfactory/Red.java new file mode 100644 index 0000000..ee9b6f3 --- /dev/null +++ b/src/com/duwei/designpattern/absfactory/Red.java @@ -0,0 +1,9 @@ +package com.duwei.designpattern.absfactory; + +public class Red implements Color { + + @Override + public void fill() { + System.out.println("Inside Red::fill() method."); + } +} \ No newline at end of file diff --git a/src/com/duwei/designpattern/absfactory/Shape.java b/src/com/duwei/designpattern/absfactory/Shape.java new file mode 100644 index 0000000..568fec5 --- /dev/null +++ b/src/com/duwei/designpattern/absfactory/Shape.java @@ -0,0 +1,5 @@ +package com.duwei.designpattern.absfactory; + +public interface Shape { + void draw(); +} diff --git a/src/com/duwei/designpattern/absfactory/ShapeFactory.java b/src/com/duwei/designpattern/absfactory/ShapeFactory.java new file mode 100644 index 0000000..e52b9e8 --- /dev/null +++ b/src/com/duwei/designpattern/absfactory/ShapeFactory.java @@ -0,0 +1,24 @@ +package com.duwei.designpattern.absfactory; + +public class ShapeFactory extends AbstractFactory { + + @Override + public Shape getShape(String shapeType){ + if(shapeType == null){ + return null; + } + if(shapeType.equalsIgnoreCase("CIRCLE")){ + return new Circle(); + } else if(shapeType.equalsIgnoreCase("RECTANGLE")){ + return new Rectangle(); + } else if(shapeType.equalsIgnoreCase("SQUARE")){ + return new Square(); + } + return null; + } + + @Override + public Color getColor(String color) { + return null; + } +} \ No newline at end of file diff --git a/src/com/duwei/designpattern/absfactory/Square.java b/src/com/duwei/designpattern/absfactory/Square.java new file mode 100644 index 0000000..b5cd00b --- /dev/null +++ b/src/com/duwei/designpattern/absfactory/Square.java @@ -0,0 +1,9 @@ +package com.duwei.designpattern.absfactory; + +public class Square implements Shape { + + @Override + public void draw() { + System.out.println("Inside Square::draw() method."); + } +} \ No newline at end of file diff --git a/src/com/duwei/designpattern/abstractfactory/Button.java b/src/com/duwei/designpattern/abstractfactory/Button.java index 2f58ecf..5cec630 100644 --- a/src/com/duwei/designpattern/abstractfactory/Button.java +++ b/src/com/duwei/designpattern/abstractfactory/Button.java @@ -1,6 +1,6 @@ package com.duwei.designpattern.abstractfactory; -//按钮接口:抽象产品 +//鎸夐挳鎺ュ彛锛氭娊璞′骇鍝 interface Button { public void display(); } diff --git a/src/com/duwei/designpattern/abstractfactory/Client.java b/src/com/duwei/designpattern/abstractfactory/Client.java index 8935cee..8049467 100644 --- a/src/com/duwei/designpattern/abstractfactory/Client.java +++ b/src/com/duwei/designpattern/abstractfactory/Client.java @@ -2,7 +2,7 @@ class Client { public static void main(String args[]) { - //使用抽象层定义 + //浣跨敤鎶借薄灞傚畾涔 SkinFactory factory; Button bt; TextField tf; diff --git a/src/com/duwei/designpattern/abstractfactory/ComboBox.java b/src/com/duwei/designpattern/abstractfactory/ComboBox.java index a5a2b36..d13843c 100644 --- a/src/com/duwei/designpattern/abstractfactory/ComboBox.java +++ b/src/com/duwei/designpattern/abstractfactory/ComboBox.java @@ -1,6 +1,6 @@ package com.duwei.designpattern.abstractfactory; -//组合框接口:抽象产品 +//缁勫悎妗嗘帴鍙o細鎶借薄浜у搧 interface ComboBox { public void display(); } \ No newline at end of file diff --git a/src/com/duwei/designpattern/abstractfactory/SkinFactory.java b/src/com/duwei/designpattern/abstractfactory/SkinFactory.java index 4187a97..496f88b 100644 --- a/src/com/duwei/designpattern/abstractfactory/SkinFactory.java +++ b/src/com/duwei/designpattern/abstractfactory/SkinFactory.java @@ -1,6 +1,6 @@ package com.duwei.designpattern.abstractfactory; -//界面皮肤工厂接口:抽象工厂 +//鐣岄潰鐨偆宸ュ巶鎺ュ彛锛氭娊璞″伐鍘 interface SkinFactory { public Button createButton(); public TextField createTextField(); diff --git a/src/com/duwei/designpattern/abstractfactory/SpringButton.java b/src/com/duwei/designpattern/abstractfactory/SpringButton.java index eb53ddb..bc4003c 100644 --- a/src/com/duwei/designpattern/abstractfactory/SpringButton.java +++ b/src/com/duwei/designpattern/abstractfactory/SpringButton.java @@ -1,8 +1,8 @@ package com.duwei.designpattern.abstractfactory; -//Spring按钮类:具体产品 +//Spring鎸夐挳绫伙細鍏蜂綋浜у搧 class SpringButton implements Button { public void display() { - System.out.println("显示浅绿色按钮。"); + System.out.println("鏄剧ず娴呯豢鑹叉寜閽"); } } \ No newline at end of file diff --git a/src/com/duwei/designpattern/abstractfactory/SpringComboBox.java b/src/com/duwei/designpattern/abstractfactory/SpringComboBox.java index a7922b2..7bef93f 100644 --- a/src/com/duwei/designpattern/abstractfactory/SpringComboBox.java +++ b/src/com/duwei/designpattern/abstractfactory/SpringComboBox.java @@ -1,8 +1,8 @@ package com.duwei.designpattern.abstractfactory; -//Spring组合框类:具体产品 +//Spring缁勫悎妗嗙被锛氬叿浣撲骇鍝 class SpringComboBox implements ComboBox { public void display() { - System.out.println("显示绿色边框组合框。"); + System.out.println("鏄剧ず缁胯壊杈规缁勫悎妗嗐"); } } diff --git a/src/com/duwei/designpattern/abstractfactory/SpringSkinFactory.java b/src/com/duwei/designpattern/abstractfactory/SpringSkinFactory.java index 8c09947..8e41fb8 100644 --- a/src/com/duwei/designpattern/abstractfactory/SpringSkinFactory.java +++ b/src/com/duwei/designpattern/abstractfactory/SpringSkinFactory.java @@ -1,6 +1,6 @@ package com.duwei.designpattern.abstractfactory; -//Spring皮肤工厂:具体工厂 +//Spring鐨偆宸ュ巶锛氬叿浣撳伐鍘 class SpringSkinFactory implements SkinFactory { public Button createButton() { return new SpringButton(); diff --git a/src/com/duwei/designpattern/abstractfactory/SpringTextField.java b/src/com/duwei/designpattern/abstractfactory/SpringTextField.java index d3c1a17..9c98e49 100644 --- a/src/com/duwei/designpattern/abstractfactory/SpringTextField.java +++ b/src/com/duwei/designpattern/abstractfactory/SpringTextField.java @@ -1,8 +1,8 @@ package com.duwei.designpattern.abstractfactory; -//Spring文本框类:具体产品 +//Spring鏂囨湰妗嗙被锛氬叿浣撲骇鍝 class SpringTextField implements TextField { public void display() { - System.out.println("显示绿色边框文本框。"); + System.out.println("鏄剧ず缁胯壊杈规鏂囨湰妗嗐"); } } \ No newline at end of file diff --git a/src/com/duwei/designpattern/abstractfactory/SummerButton.java b/src/com/duwei/designpattern/abstractfactory/SummerButton.java index c3df996..19ceaee 100644 --- a/src/com/duwei/designpattern/abstractfactory/SummerButton.java +++ b/src/com/duwei/designpattern/abstractfactory/SummerButton.java @@ -1,8 +1,8 @@ package com.duwei.designpattern.abstractfactory; -//Summer按钮类:具体产品 +//Summer鎸夐挳绫伙細鍏蜂綋浜у搧 class SummerButton implements Button { public void display() { - System.out.println("显示浅蓝色按钮。"); + System.out.println("鏄剧ず娴呰摑鑹叉寜閽"); } } diff --git a/src/com/duwei/designpattern/abstractfactory/SummerComboBox.java b/src/com/duwei/designpattern/abstractfactory/SummerComboBox.java index 7185787..32261b4 100644 --- a/src/com/duwei/designpattern/abstractfactory/SummerComboBox.java +++ b/src/com/duwei/designpattern/abstractfactory/SummerComboBox.java @@ -1,8 +1,8 @@ package com.duwei.designpattern.abstractfactory; -//Summer组合框类:具体产品 +//Summer缁勫悎妗嗙被锛氬叿浣撲骇鍝 class SummerComboBox implements ComboBox { public void display() { - System.out.println("显示蓝色边框组合框。"); + System.out.println("鏄剧ず钃濊壊杈规缁勫悎妗嗐"); } } diff --git a/src/com/duwei/designpattern/abstractfactory/SummerSkinFactory.java b/src/com/duwei/designpattern/abstractfactory/SummerSkinFactory.java index b1d7447..e0cc171 100644 --- a/src/com/duwei/designpattern/abstractfactory/SummerSkinFactory.java +++ b/src/com/duwei/designpattern/abstractfactory/SummerSkinFactory.java @@ -1,6 +1,6 @@ package com.duwei.designpattern.abstractfactory; -//Summer皮肤工厂:具体工厂 +//Summer鐨偆宸ュ巶锛氬叿浣撳伐鍘 class SummerSkinFactory implements SkinFactory { public Button createButton() { return new SummerButton(); diff --git a/src/com/duwei/designpattern/abstractfactory/SummerTextField.java b/src/com/duwei/designpattern/abstractfactory/SummerTextField.java index c5819d4..19c8489 100644 --- a/src/com/duwei/designpattern/abstractfactory/SummerTextField.java +++ b/src/com/duwei/designpattern/abstractfactory/SummerTextField.java @@ -1,8 +1,8 @@ package com.duwei.designpattern.abstractfactory; -//Summer文本框类:具体产品 +//Summer鏂囨湰妗嗙被锛氬叿浣撲骇鍝 class SummerTextField implements TextField { public void display() { - System.out.println("显示蓝色边框文本框。"); + System.out.println("鏄剧ず钃濊壊杈规鏂囨湰妗嗐"); } } diff --git a/src/com/duwei/designpattern/abstractfactory/TextField.java b/src/com/duwei/designpattern/abstractfactory/TextField.java index eb9bbe3..fe94d6a 100644 --- a/src/com/duwei/designpattern/abstractfactory/TextField.java +++ b/src/com/duwei/designpattern/abstractfactory/TextField.java @@ -1,6 +1,6 @@ package com.duwei.designpattern.abstractfactory; -//文本框接口:抽象产品 +//鏂囨湰妗嗘帴鍙o細鎶借薄浜у搧 interface TextField { public void display(); } diff --git a/src/com/duwei/designpattern/abstractfactory/XMLUtil.java b/src/com/duwei/designpattern/abstractfactory/XMLUtil.java index 37df045..fe2af77 100644 --- a/src/com/duwei/designpattern/abstractfactory/XMLUtil.java +++ b/src/com/duwei/designpattern/abstractfactory/XMLUtil.java @@ -8,21 +8,21 @@ import java.io.*; public class XMLUtil { - //该方法用于从XML配置文件中提取具体类类名,并返回一个实例对象 + //璇ユ柟娉曠敤浜庝粠XML閰嶇疆鏂囦欢涓彁鍙栧叿浣撶被绫诲悕锛屽苟杩斿洖涓涓疄渚嬪璞 public static Object getBean() { try { - //创建文档对象 + //鍒涘缓鏂囨。瀵硅薄 DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = dFactory.newDocumentBuilder(); Document doc; doc = builder.parse(new File("src\\com\\duwei\\designpattern\\abstractfactory\\config.xml")); - //获取包含类名的文本节点 + //鑾峰彇鍖呭惈绫诲悕鐨勬枃鏈妭鐐 NodeList nl = doc.getElementsByTagName("className"); Node classNode=nl.item(0).getFirstChild(); String cName=classNode.getNodeValue(); - //通过类名生成实例对象并将其返回 + //閫氳繃绫诲悕鐢熸垚瀹炰緥瀵硅薄骞跺皢鍏惰繑鍥 Class c=Class.forName(cName); Object obj=c.newInstance(); return obj; diff --git a/src/com/duwei/designpattern/adapter/BinarySearch.java b/src/com/duwei/designpattern/adapter/BinarySearch.java index 5b193f9..286c19f 100644 --- a/src/com/duwei/designpattern/adapter/BinarySearch.java +++ b/src/com/duwei/designpattern/adapter/BinarySearch.java @@ -1,6 +1,6 @@ package com.duwei.designpattern.adapter; -//二分查找类:适配者 +//浜屽垎鏌ユ壘绫伙細閫傞厤鑰 class BinarySearch { public int binarySearch(int array[], int key) { int low = 0; @@ -13,9 +13,9 @@ public int binarySearch(int array[], int key) { } else if (midVal > key) { high = mid - 1; } else { - return 1; // 找到元素返回1 + return 1; // 鎵惧埌鍏冪礌杩斿洖1 } } - return -1; // 未找到元素返回-1 + return -1; // 鏈壘鍒板厓绱犺繑鍥-1 } } diff --git a/src/com/duwei/designpattern/adapter/OperationAdapter.java b/src/com/duwei/designpattern/adapter/OperationAdapter.java index 1645fa3..561bad1 100644 --- a/src/com/duwei/designpattern/adapter/OperationAdapter.java +++ b/src/com/duwei/designpattern/adapter/OperationAdapter.java @@ -1,9 +1,9 @@ package com.duwei.designpattern.adapter; -//操作适配器:适配器 +//鎿嶄綔閫傞厤鍣細閫傞厤鍣 class OperationAdapter implements ScoreOperation { - private QuickSort sortObj; // 定义适配者QuickSort对象 - private BinarySearch searchObj; // 定义适配者BinarySearch对象 + private QuickSort sortObj; // 瀹氫箟閫傞厤鑰匭uickSort瀵硅薄 + private BinarySearch searchObj; // 瀹氫箟閫傞厤鑰匓inarySearch瀵硅薄 public OperationAdapter() { sortObj = new QuickSort(); @@ -11,10 +11,10 @@ public OperationAdapter() { } public int[] sort(int array[]) { - return sortObj.quickSort(array); // 调用适配者类QuickSort的排序方法 + return sortObj.quickSort(array); // 璋冪敤閫傞厤鑰呯被QuickSort鐨勬帓搴忔柟娉 } public int search(int array[], int key) { - return searchObj.binarySearch(array, key); // 调用适配者类BinarySearch的查找方法 + return searchObj.binarySearch(array, key); // 璋冪敤閫傞厤鑰呯被BinarySearch鐨勬煡鎵炬柟娉 } } \ No newline at end of file diff --git a/src/com/duwei/designpattern/adapter/QuickSort.java b/src/com/duwei/designpattern/adapter/QuickSort.java index a6f0841..0501ae5 100644 --- a/src/com/duwei/designpattern/adapter/QuickSort.java +++ b/src/com/duwei/designpattern/adapter/QuickSort.java @@ -1,6 +1,6 @@ package com.duwei.designpattern.adapter; -//快速排序类:适配者 +//蹇熸帓搴忕被锛氶傞厤鑰 class QuickSort { public int[] quickSort(int array[]) { sort(array, 0, array.length - 1); diff --git a/src/com/duwei/designpattern/adapter/ScoreOperation.java b/src/com/duwei/designpattern/adapter/ScoreOperation.java index 1de1e7f..8322980 100644 --- a/src/com/duwei/designpattern/adapter/ScoreOperation.java +++ b/src/com/duwei/designpattern/adapter/ScoreOperation.java @@ -1,8 +1,8 @@ package com.duwei.designpattern.adapter; -//抽象成绩操作类:目标接口 +//鎶借薄鎴愮哗鎿嶄綔绫伙細鐩爣鎺ュ彛 interface ScoreOperation { - public int[] sort(int array[]); //成绩排序 + public int[] sort(int array[]); //鎴愮哗鎺掑簭 - public int search(int array[],int key); //成绩查找 + public int search(int array[],int key); //鎴愮哗鏌ユ壘 } \ No newline at end of file diff --git a/src/com/duwei/designpattern/chain/chain1/Client.java b/src/com/duwei/designpattern/chain/chain1/Client.java new file mode 100644 index 0000000..ef422ee --- /dev/null +++ b/src/com/duwei/designpattern/chain/chain1/Client.java @@ -0,0 +1,22 @@ +package com.duwei.designpattern.chain.chain1; + +import java.util.ArrayList; +import java.util.List; + +public class Client { + + public static void main(String[] args) { + //1.鏋勫缓璐d换閾 + List ratifies = new ArrayList<>(); + ratifies.add(new Leader()); + ratifies.add(new Manager()); + ratifies.add(new Header()); + //鏋勫缓璇锋眰瀵硅薄 + Request request = new Request.Builder().setDays(7).setName("aaa").setReason("鐢熺梾").build(); + //缁勮澶勭悊 + RealChain realChain = new RealChain(ratifies, request, 0); + realChain.proceed(request); + + } + +} diff --git a/src/com/duwei/designpattern/chain/chain1/Header.java b/src/com/duwei/designpattern/chain/chain1/Header.java new file mode 100644 index 0000000..d6fab8e --- /dev/null +++ b/src/com/duwei/designpattern/chain/chain1/Header.java @@ -0,0 +1,14 @@ +package com.duwei.designpattern.chain.chain1; + +public class Header implements Ratify { + + @Override + public Result deal(Chain chain) { + Request request = chain.request(); + System.out.println("DepartmentHeader=====>request:" + request.toString()); + if (request.getDays() > 7) { + return new Result(false, "浣犺繖涓畬鍏ㄦ病蹇呰"); + } + return new Result(true, "DepartmentHeader锛氫笉瑕佺潃鎬ワ紝鎶婁簨鎯呭鐞嗗畬鍐嶅洖鏉ワ紒"); + } +} diff --git a/src/com/duwei/designpattern/chain/chain1/Leader.java b/src/com/duwei/designpattern/chain/chain1/Leader.java new file mode 100644 index 0000000..a06ddd1 --- /dev/null +++ b/src/com/duwei/designpattern/chain/chain1/Leader.java @@ -0,0 +1,19 @@ +package com.duwei.designpattern.chain.chain1; + +public class Leader implements Ratify { + @Override + public Result deal(Chain chain) { + Request request = chain.request(); + System.out.println("GroupLeader=====>request:" + request.toString()); + + if (request.getDays() > 1) { + // 鍖呰鏂扮殑Request瀵硅薄 + Request newRequest = new Request.Builder().newRequest(request) + .setManagerInfo(request.getName() + "骞虫椂琛ㄧ幇涓嶉敊锛岃屼笖鐜板湪椤圭洰涔熶笉蹇") + .build(); + return chain.proceed(newRequest); + } + return new Result(true, "GroupLeader锛氭棭鍘绘棭鍥"); + } + +} diff --git a/src/com/duwei/designpattern/chain/chain1/Manager.java b/src/com/duwei/designpattern/chain/chain1/Manager.java new file mode 100644 index 0000000..cbe97f9 --- /dev/null +++ b/src/com/duwei/designpattern/chain/chain1/Manager.java @@ -0,0 +1,21 @@ +package com.duwei.designpattern.chain.chain1; + + +public class Manager implements Ratify { + + @Override + public Result deal(Chain chain) { + Request request = chain.request(); + System.out.println("Manager=====>request:" + request.toString()); + if (request.getDays() > 3) { + // 鏋勫缓鏂扮殑Request + Request newRequest = new Request.Builder().newRequest(request) + .setManagerInfo(request.getName() + "姣忔湀鐨凨PI鑰冩牳杩樹笉閿欙紝鍙互鎵瑰噯") + .build(); + return chain.proceed(newRequest); + + } + return new Result(true, "Manager锛氭棭鐐规妸浜嬫儏鍔炲畬锛岄」鐩涓嶅紑浣"); + } + +} diff --git a/src/com/duwei/designpattern/chain/chain1/Ratify.java b/src/com/duwei/designpattern/chain/chain1/Ratify.java new file mode 100644 index 0000000..f9ec85a --- /dev/null +++ b/src/com/duwei/designpattern/chain/chain1/Ratify.java @@ -0,0 +1,17 @@ +package com.duwei.designpattern.chain.chain1; + +public interface Ratify { + Result deal(Chain chain); + + /** + * 鎺ュ彛鎻忚堪锛氬request鍜孯esult灏佽锛岀敤鏉ヨ浆鍙 + */ + interface Chain { + // 鑾峰彇褰撳墠request + Request request(); + + // 杞彂request + Result proceed(Request request); + } + +} diff --git a/src/com/duwei/designpattern/chain/chain1/RealChain.java b/src/com/duwei/designpattern/chain/chain1/RealChain.java new file mode 100644 index 0000000..0441f3f --- /dev/null +++ b/src/com/duwei/designpattern/chain/chain1/RealChain.java @@ -0,0 +1,47 @@ +package com.duwei.designpattern.chain.chain1; + +import java.util.List; + +public class RealChain implements Ratify.Chain { + public Request request; + public List ratifyList; + public int index; + + /** + * 鏋勯犳柟娉 + * + * @param ratifyList Ratify鎺ュ彛鐨勫疄鐜扮被闆嗗悎 + * @param request 鍏蜂綋鐨勮姹俁equest瀹炰緥 + * @param index 宸茬粡澶勭悊杩囪request鐨勮矗浠讳汉鏁伴噺 + */ + public RealChain(List ratifyList, Request request, int index) { + this.ratifyList = ratifyList; + this.request = request; + this.index = index; + } + + /** + * 鏂规硶鎻忚堪锛氬叿浣撹浆鍙戝姛鑳 + */ + @Override + public Result proceed(Request request) { + Result proceed = null; + if (ratifyList.size() > index) { + RealChain realChain = new RealChain(ratifyList, request, index + 1); + Ratify ratify = ratifyList.get(index); + proceed = ratify.deal(realChain); + } + + return proceed; + } + + /** + * 鏂规硶鎻忚堪锛氳繑鍥炲綋鍓峈equest瀵硅薄鎴栬呰繑鍥炲綋鍓嶈繘琛屽寘瑁呭悗鐨凴equest瀵硅薄 + */ + @Override + public Request request() { + return request; + } + + +} diff --git a/src/com/duwei/designpattern/chain/chain1/Request.java b/src/com/duwei/designpattern/chain/chain1/Request.java new file mode 100644 index 0000000..3b3ac07 --- /dev/null +++ b/src/com/duwei/designpattern/chain/chain1/Request.java @@ -0,0 +1,181 @@ +package com.duwei.designpattern.chain.chain1; + +/** + * 浣跨敤寤洪犺呮ā寮忔瀯寤轰竴涓鍋囧璞 + */ +public class Request { + /** + * 璇峰亣浜虹殑濮撳悕 + */ + private String name; + /** + * 璇峰亣鍘熷洜 + */ + private String reason; + /** + * 璇峰亣澶╂暟 + */ + private int days; + /** + * 涓绾eader鎰忚 + */ + private String leaderInfo; + /** + * 浜岀骇leader鎰忚 + */ + private String managerInfo; + /** + * 涓夌骇leader鎰忚 + */ + private String headerInfo; + + public Request(Builder builder) { + this.name = builder.name; + this.reason = builder.reason; + this.days = builder.days; + this.leaderInfo = builder.leaderInfo; + this.managerInfo = builder.managerInfo; + this.headerInfo = builder.headerInfo; + } + + public static class Builder { + /** + * 璇峰亣浜虹殑濮撳悕 + */ + private String name; + /** + * 璇峰亣鍘熷洜 + */ + private String reason; + /** + * 璇峰亣澶╂暟 + */ + private int days; + /** + * 涓绾eader鎰忚 + */ + private String leaderInfo; + /** + * 浜岀骇leader鎰忚 + */ + private String managerInfo; + /** + * 涓夌骇leader鎰忚 + */ + private String headerInfo; + + public Builder() { + } + + public Builder newRequest(Request request) { + this.name = request.name; + this.days = request.days; + this.reason = request.reason; + if (request.getLeaderInfo() != null + && !request.getLeaderInfo().equals("")) { + this.leaderInfo = request.leaderInfo; + } + + if (request.managerInfo != null && !request.managerInfo.equals("")) { + this.managerInfo = request.managerInfo; + } + + if (request.headerInfo != null + && !request.headerInfo.equals("")) { + this.headerInfo = request.headerInfo; + } + +// if (request.customInfo != null && !request.customInfo.equals("")) { +// this.customInfo = request.customInfo; +// } + + return this; + } + + + public Builder setName(String name) { + this.name = name; + return this; + } + + public Builder setReason(String reason) { + this.reason = reason; + return this; + } + + public Builder setDays(int days) { + this.days = days; + return this; + } + + public Builder setLeaderInfo(String leaderInfo) { + this.leaderInfo = leaderInfo; + return this; + } + + public Builder setManagerInfo(String managerInfo) { + this.managerInfo = managerInfo; + return this; + } + + public Builder setHeaderInfo(String headerInfo) { + this.headerInfo = headerInfo; + return this; + } + + public Request build() { + return new Request(this); + } + + } + + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getReason() { + return reason; + } + + public void setReason(String reason) { + this.reason = reason; + } + + public int getDays() { + return days; + } + + public void setDays(int days) { + this.days = days; + } + + public String getLeaderInfo() { + return leaderInfo; + } + + public void setLeaderInfo(String leaderInfo) { + this.leaderInfo = leaderInfo; + } + + public String getManagerInfo() { + return managerInfo; + } + + public void setManagerInfo(String managerInfo) { + this.managerInfo = managerInfo; + } + + public String getHeaderInfo() { + return headerInfo; + } + + public void setHeaderInfo(String headerInfo) { + this.headerInfo = headerInfo; + } +} diff --git a/src/com/duwei/designpattern/chain/chain1/Result.java b/src/com/duwei/designpattern/chain/chain1/Result.java new file mode 100644 index 0000000..f86ec35 --- /dev/null +++ b/src/com/duwei/designpattern/chain/chain1/Result.java @@ -0,0 +1,42 @@ +package com.duwei.designpattern.chain.chain1; + +/** + * 璇峰亣缁撴灉 + */ +public class Result { + + public boolean isAgree; + public String info; + + public Result(){} + + public Result(boolean isAgree , String info){ + this.isAgree = isAgree; + this.info = info; + } + + public boolean isAgree() { + return isAgree; + } + + public void setAgree(boolean agree) { + isAgree = agree; + } + + public String getInfo() { + return info; + } + + public void setInfo(String info) { + this.info = info; + } + + @Override + public String toString() { + return "Result{" + + "isAgree=" + isAgree + + ", info='" + info + '\'' + + '}'; + } + +} diff --git a/src/com/duwei/designpattern/chain/chain2/AbstractHandler.java b/src/com/duwei/designpattern/chain/chain2/AbstractHandler.java new file mode 100644 index 0000000..6ef7180 --- /dev/null +++ b/src/com/duwei/designpattern/chain/chain2/AbstractHandler.java @@ -0,0 +1,20 @@ +package com.duwei.designpattern.chain.chain2; + +/** + * + */ +public abstract class AbstractHandler { + private AbstractHandler handler; + + public abstract void handleRequest(String condition); + + public AbstractHandler getHandler() { + return handler; + } + + public void setHandler(AbstractHandler handler) { + this.handler = handler; + } + + +} diff --git a/src/com/duwei/designpattern/chain/chain2/Client.java b/src/com/duwei/designpattern/chain/chain2/Client.java new file mode 100644 index 0000000..853b361 --- /dev/null +++ b/src/com/duwei/designpattern/chain/chain2/Client.java @@ -0,0 +1,14 @@ +package com.duwei.designpattern.chain.chain2; + +public class Client { + + public static void main(String[] args) { + AbstractHandler A = new ConcreteHandlerA(); + AbstractHandler B = new ConcreteHandlerB(); + AbstractHandler Z = new ConcreteHandlerZ(); + + A.setHandler(B); + B.setHandler(Z); + A.handleRequest("Z"); + } +} diff --git a/src/com/duwei/designpattern/chain/chain2/ConcreteHandlerA.java b/src/com/duwei/designpattern/chain/chain2/ConcreteHandlerA.java new file mode 100644 index 0000000..0fc9f0c --- /dev/null +++ b/src/com/duwei/designpattern/chain/chain2/ConcreteHandlerA.java @@ -0,0 +1,12 @@ +package com.duwei.designpattern.chain.chain2; + +public class ConcreteHandlerA extends AbstractHandler { + @Override + public void handleRequest(String condition) { + if (condition.equals("A")){ + System.out.println("A澶勭悊"); + }else{ + super.getHandler().handleRequest(condition); + } + } +} diff --git a/src/com/duwei/designpattern/chain/chain2/ConcreteHandlerB.java b/src/com/duwei/designpattern/chain/chain2/ConcreteHandlerB.java new file mode 100644 index 0000000..acf371e --- /dev/null +++ b/src/com/duwei/designpattern/chain/chain2/ConcreteHandlerB.java @@ -0,0 +1,12 @@ +package com.duwei.designpattern.chain.chain2; + +public class ConcreteHandlerB extends AbstractHandler { + @Override + public void handleRequest(String condition) { + if (condition.equals("B")) { + System.out.println("B澶勭悊"); + } else { + super.getHandler().handleRequest(condition); + } + } +} diff --git a/src/com/duwei/designpattern/chain/chain2/ConcreteHandlerZ.java b/src/com/duwei/designpattern/chain/chain2/ConcreteHandlerZ.java new file mode 100644 index 0000000..d11e112 --- /dev/null +++ b/src/com/duwei/designpattern/chain/chain2/ConcreteHandlerZ.java @@ -0,0 +1,8 @@ +package com.duwei.designpattern.chain.chain2; + +public class ConcreteHandlerZ extends AbstractHandler { + @Override + public void handleRequest(String condition) { + System.out.println("鏈鍚庝竴涓鐞"); + } +} diff --git a/src/com/duwei/designpattern/decoration/Main.java b/src/com/duwei/designpattern/decoration/Main.java new file mode 100644 index 0000000..6942b0b --- /dev/null +++ b/src/com/duwei/designpattern/decoration/Main.java @@ -0,0 +1,10 @@ +package com.duwei.designpattern.decoration; + +/** + * 瑁呴グ鍣ㄦā寮 + */ +public class Main { + public static void main(String[] args) { + + } +} diff --git a/src/com/duwei/designpattern/factorymethod/Client.java b/src/com/duwei/designpattern/factorymethod/Client.java index 0c21a10..6e5b400 100644 --- a/src/com/duwei/designpattern/factorymethod/Client.java +++ b/src/com/duwei/designpattern/factorymethod/Client.java @@ -4,7 +4,7 @@ class Client { public static void main(String args[]) { LoggerFactory factory; Logger logger; - factory = new FileLoggerFactory(); //可引入配置文件实现 + factory = new FileLoggerFactory(); //鍙紩鍏ラ厤缃枃浠跺疄鐜 logger = factory.createLogger(); logger.writeLog(); } diff --git a/src/com/duwei/designpattern/factorymethod/DatabaseLogger.java b/src/com/duwei/designpattern/factorymethod/DatabaseLogger.java index 087705e..4ea6696 100644 --- a/src/com/duwei/designpattern/factorymethod/DatabaseLogger.java +++ b/src/com/duwei/designpattern/factorymethod/DatabaseLogger.java @@ -1,8 +1,8 @@ package com.duwei.designpattern.factorymethod; -//数据库日志记录器:具体产品 +//鏁版嵁搴撴棩蹇楄褰曞櫒锛氬叿浣撲骇鍝 class DatabaseLogger implements Logger { public void writeLog() { - System.out.println("数据库日志记录。"); + System.out.println("鏁版嵁搴撴棩蹇楄褰曘"); } } diff --git a/src/com/duwei/designpattern/factorymethod/DatabaseLoggerFactory.java b/src/com/duwei/designpattern/factorymethod/DatabaseLoggerFactory.java index cf30da6..31141fa 100644 --- a/src/com/duwei/designpattern/factorymethod/DatabaseLoggerFactory.java +++ b/src/com/duwei/designpattern/factorymethod/DatabaseLoggerFactory.java @@ -1,12 +1,12 @@ package com.duwei.designpattern.factorymethod; -//数据库日志记录器工厂类:具体工厂 +//鏁版嵁搴撴棩蹇楄褰曞櫒宸ュ巶绫伙細鍏蜂綋宸ュ巶 class DatabaseLoggerFactory implements LoggerFactory { public Logger createLogger() { - //连接数据库,代码省略 - //创建数据库日志记录器对象 + //杩炴帴鏁版嵁搴擄紝浠g爜鐪佺暐 + //鍒涘缓鏁版嵁搴撴棩蹇楄褰曞櫒瀵硅薄 Logger logger = new DatabaseLogger(); - //初始化数据库日志记录器,代码省略 + //鍒濆鍖栨暟鎹簱鏃ュ織璁板綍鍣紝浠g爜鐪佺暐 return logger; } } diff --git a/src/com/duwei/designpattern/factorymethod/FileLogger.java b/src/com/duwei/designpattern/factorymethod/FileLogger.java index 9e61157..bedf0a6 100644 --- a/src/com/duwei/designpattern/factorymethod/FileLogger.java +++ b/src/com/duwei/designpattern/factorymethod/FileLogger.java @@ -1,8 +1,8 @@ package com.duwei.designpattern.factorymethod; -//文件日志记录器:具体产品 +//鏂囦欢鏃ュ織璁板綍鍣細鍏蜂綋浜у搧 class FileLogger implements Logger { public void writeLog() { - System.out.println("文件日志记录。"); + System.out.println("鏂囦欢鏃ュ織璁板綍銆"); } } \ No newline at end of file diff --git a/src/com/duwei/designpattern/factorymethod/FileLoggerFactory.java b/src/com/duwei/designpattern/factorymethod/FileLoggerFactory.java index 4682587..a01dc2d 100644 --- a/src/com/duwei/designpattern/factorymethod/FileLoggerFactory.java +++ b/src/com/duwei/designpattern/factorymethod/FileLoggerFactory.java @@ -1,11 +1,11 @@ package com.duwei.designpattern.factorymethod; -//文件日志记录器工厂类:具体工厂 +//鏂囦欢鏃ュ織璁板綍鍣ㄥ伐鍘傜被锛氬叿浣撳伐鍘 class FileLoggerFactory implements LoggerFactory { public Logger createLogger() { - //创建文件日志记录器对象 + //鍒涘缓鏂囦欢鏃ュ織璁板綍鍣ㄥ璞 Logger logger = new FileLogger(); - //创建文件,代码省略 + //鍒涘缓鏂囦欢锛屼唬鐮佺渷鐣 return logger; } } diff --git a/src/com/duwei/designpattern/factorymethod/Logger.java b/src/com/duwei/designpattern/factorymethod/Logger.java index 6c23b92..9097fa2 100644 --- a/src/com/duwei/designpattern/factorymethod/Logger.java +++ b/src/com/duwei/designpattern/factorymethod/Logger.java @@ -1,6 +1,6 @@ package com.duwei.designpattern.factorymethod; -//日志记录器接口:抽象产品 +//鏃ュ織璁板綍鍣ㄦ帴鍙o細鎶借薄浜у搧 interface Logger { public void writeLog(); } \ No newline at end of file diff --git a/src/com/duwei/designpattern/factorymethod/LoggerFactory.java b/src/com/duwei/designpattern/factorymethod/LoggerFactory.java index 238cdae..6b30f6f 100644 --- a/src/com/duwei/designpattern/factorymethod/LoggerFactory.java +++ b/src/com/duwei/designpattern/factorymethod/LoggerFactory.java @@ -1,6 +1,6 @@ package com.duwei.designpattern.factorymethod; -//日志记录器工厂接口:抽象工厂 +//鏃ュ織璁板綍鍣ㄥ伐鍘傛帴鍙o細鎶借薄宸ュ巶 interface LoggerFactory { public Logger createLogger(); } \ No newline at end of file diff --git a/src/com/duwei/designpattern/observer/BinaryObserver.java b/src/com/duwei/designpattern/observer/BinaryObserver.java new file mode 100644 index 0000000..edbc3a9 --- /dev/null +++ b/src/com/duwei/designpattern/observer/BinaryObserver.java @@ -0,0 +1,15 @@ +package com.duwei.designpattern.observer; + +public class BinaryObserver extends Observer{ + + public BinaryObserver(Subject subject){ + this.subject = subject; + this.subject.attach(this); + } + + @Override + public void update() { + System.out.println( "Binary String: " + + Integer.toBinaryString( subject.getState() ) ); + } +} \ No newline at end of file diff --git a/src/com/duwei/designpattern/observer/HexaObserver.java b/src/com/duwei/designpattern/observer/HexaObserver.java new file mode 100644 index 0000000..d6d2917 --- /dev/null +++ b/src/com/duwei/designpattern/observer/HexaObserver.java @@ -0,0 +1,15 @@ +package com.duwei.designpattern.observer; + +public class HexaObserver extends Observer{ + + public HexaObserver(Subject subject){ + this.subject = subject; + this.subject.attach(this); + } + + @Override + public void update() { + System.out.println( "Hex String: " + + Integer.toHexString( subject.getState() ).toUpperCase() ); + } +} \ No newline at end of file diff --git a/src/com/duwei/designpattern/observer/Observer.java b/src/com/duwei/designpattern/observer/Observer.java new file mode 100644 index 0000000..17def94 --- /dev/null +++ b/src/com/duwei/designpattern/observer/Observer.java @@ -0,0 +1,6 @@ +package com.duwei.designpattern.observer; + +public abstract class Observer { + protected Subject subject; + public abstract void update(); +} \ No newline at end of file diff --git a/src/com/duwei/designpattern/observer/ObserverPatternDemo.java b/src/com/duwei/designpattern/observer/ObserverPatternDemo.java new file mode 100644 index 0000000..b12684d --- /dev/null +++ b/src/com/duwei/designpattern/observer/ObserverPatternDemo.java @@ -0,0 +1,16 @@ +package com.duwei.designpattern.observer; + +public class ObserverPatternDemo { + public static void main(String[] args) { + Subject subject = new Subject(); + + new HexaObserver(subject); + new OctalObserver(subject); + new BinaryObserver(subject); + + System.out.println("First state change: 15"); + subject.setState(15); + System.out.println("Second state change: 10"); + subject.setState(10); + } +} \ No newline at end of file diff --git a/src/com/duwei/designpattern/observer/OctalObserver.java b/src/com/duwei/designpattern/observer/OctalObserver.java new file mode 100644 index 0000000..64cdc05 --- /dev/null +++ b/src/com/duwei/designpattern/observer/OctalObserver.java @@ -0,0 +1,15 @@ +package com.duwei.designpattern.observer; + +public class OctalObserver extends Observer{ + + public OctalObserver(Subject subject){ + this.subject = subject; + this.subject.attach(this); + } + + @Override + public void update() { + System.out.println( "Octal String: " + + Integer.toOctalString( subject.getState() ) ); + } +} \ No newline at end of file diff --git a/src/com/duwei/designpattern/observer/Subject.java b/src/com/duwei/designpattern/observer/Subject.java new file mode 100644 index 0000000..fcbdd21 --- /dev/null +++ b/src/com/duwei/designpattern/observer/Subject.java @@ -0,0 +1,29 @@ +package com.duwei.designpattern.observer; + +import java.util.ArrayList; +import java.util.List; + +public class Subject { + + private List observers = new ArrayList(); + private int state; + + public int getState() { + return state; + } + + public void setState(int state) { + this.state = state; + notifyAllObservers(); + } + + public void attach(Observer observer){ + observers.add(observer); + } + + public void notifyAllObservers(){ + for (Observer observer : observers) { + observer.update(); + } + } +} \ No newline at end of file diff --git a/src/com/duwei/designpattern/proxy/staticproxy/Main.java b/src/com/duwei/designpattern/proxy/staticproxy/Main.java new file mode 100644 index 0000000..3d05b01 --- /dev/null +++ b/src/com/duwei/designpattern/proxy/staticproxy/Main.java @@ -0,0 +1,20 @@ +package com.duwei.designpattern.proxy.staticproxy; + +/** + * 闈欐佷唬鐞 + * + * 1.瀹炵幇鍏卞悓鎺ュ彛锛屾垨鎶借薄绫 + * + * 2.浠g悊绫绘寔鏈夎浠g悊绫荤殑鎶借薄寮曠敤 + */ +public class Main { + + public static void main(String[] args) { + + Proxy proxy = new Proxy(); + + proxy.proxyMethod(); + + } + +} diff --git a/src/com/duwei/designpattern/proxy/staticproxy/Proxy.java b/src/com/duwei/designpattern/proxy/staticproxy/Proxy.java new file mode 100644 index 0000000..9005cdf --- /dev/null +++ b/src/com/duwei/designpattern/proxy/staticproxy/Proxy.java @@ -0,0 +1,15 @@ +package com.duwei.designpattern.proxy.staticproxy; + +public class Proxy implements ProxyInterface { + //杩欓噷鎸佹湁鐪熸瀵硅薄鐨勫紩鐢ㄦ洿娓呮櫚锛屾敞鎰忓拰瑁呴グ鍣ㄧ殑鍖哄埆 + private Target target; + + public Proxy() { + this.target = new Target(); + } + + @Override + public void proxyMethod() { + target.proxyMethod(); + } +} diff --git a/src/com/duwei/designpattern/proxy/staticproxy/ProxyInterface.java b/src/com/duwei/designpattern/proxy/staticproxy/ProxyInterface.java new file mode 100644 index 0000000..eea6552 --- /dev/null +++ b/src/com/duwei/designpattern/proxy/staticproxy/ProxyInterface.java @@ -0,0 +1,7 @@ +package com.duwei.designpattern.proxy.staticproxy; + +public interface ProxyInterface { + + void proxyMethod(); + +} diff --git a/src/com/duwei/designpattern/proxy/staticproxy/Target.java b/src/com/duwei/designpattern/proxy/staticproxy/Target.java new file mode 100644 index 0000000..71783a6 --- /dev/null +++ b/src/com/duwei/designpattern/proxy/staticproxy/Target.java @@ -0,0 +1,8 @@ +package com.duwei.designpattern.proxy.staticproxy; + +public class Target implements ProxyInterface { + @Override + public void proxyMethod() { + System.out.println("鎴戞槸琚唬鐞嗙被"); + } +} diff --git a/src/com/duwei/designpattern/simplefictory/Chart.java b/src/com/duwei/designpattern/simplefictory/Chart.java index d224b75..2b5a1f8 100644 --- a/src/com/duwei/designpattern/simplefictory/Chart.java +++ b/src/com/duwei/designpattern/simplefictory/Chart.java @@ -1,6 +1,6 @@ package com.duwei.designpattern.simplefictory; -//抽象图表接口:抽象产品类 +//鎶借薄鍥捐〃鎺ュ彛锛氭娊璞′骇鍝佺被 interface Chart { public void display(); } \ No newline at end of file diff --git a/src/com/duwei/designpattern/simplefictory/ChartFactory.java b/src/com/duwei/designpattern/simplefictory/ChartFactory.java index 047a557..c2e68f9 100644 --- a/src/com/duwei/designpattern/simplefictory/ChartFactory.java +++ b/src/com/duwei/designpattern/simplefictory/ChartFactory.java @@ -1,22 +1,20 @@ package com.duwei.designpattern.simplefictory; -//图表工厂类:工厂类 -class ChartFactory { - //静态工厂方法 - public static Chart getChart(String type) { - Chart chart = null; - if (type.equalsIgnoreCase("histogram")) { - chart = new HistogramChart(); - System.out.println("初始化设置柱状图!"); - } - else if (type.equalsIgnoreCase("pie")) { - chart = new PieChart(); - System.out.println("初始化设置饼状图!"); - } - else if (type.equalsIgnoreCase("line")) { - chart = new LineChart(); - System.out.println("初始化设置折线图!"); - } - return chart; - } +//鍥捐〃宸ュ巶绫伙細宸ュ巶绫 +class ChartFactory { + //闈欐佸伐鍘傛柟娉 + public static Chart getChart(String type) { + Chart chart = null; + if (type.equalsIgnoreCase("histogram")) { + chart = new HistogramChart(); + System.out.println("鍒濆鍖栬缃煴鐘跺浘锛"); + } else if (type.equalsIgnoreCase("pie")) { + chart = new PieChart(); + System.out.println("鍒濆鍖栬缃ゼ鐘跺浘锛"); + } else if (type.equalsIgnoreCase("line")) { + chart = new LineChart(); + System.out.println("鍒濆鍖栬缃姌绾垮浘锛"); + } + return chart; + } } \ No newline at end of file diff --git a/src/com/duwei/designpattern/simplefictory/Client.java b/src/com/duwei/designpattern/simplefictory/Client.java index 8cfa171..f6f0a3f 100644 --- a/src/com/duwei/designpattern/simplefictory/Client.java +++ b/src/com/duwei/designpattern/simplefictory/Client.java @@ -3,7 +3,7 @@ class Client { public static void main(String args[]) { Chart chart; - chart = ChartFactory.getChart("histogram"); //通过静态工厂方法创建产品 + chart = ChartFactory.getChart("histogram"); //閫氳繃闈欐佸伐鍘傛柟娉曞垱寤轰骇鍝 chart.display(); } } diff --git a/src/com/duwei/designpattern/simplefictory/HistogramChart.java b/src/com/duwei/designpattern/simplefictory/HistogramChart.java index ad46314..6fd00a2 100644 --- a/src/com/duwei/designpattern/simplefictory/HistogramChart.java +++ b/src/com/duwei/designpattern/simplefictory/HistogramChart.java @@ -1,12 +1,12 @@ package com.duwei.designpattern.simplefictory; -//柱状图类:具体产品类 +//鏌辩姸鍥剧被锛氬叿浣撲骇鍝佺被 class HistogramChart implements Chart { public HistogramChart() { - System.out.println("创建柱状图!"); + System.out.println("鍒涘缓鏌辩姸鍥撅紒"); } public void display() { - System.out.println("显示柱状图!"); + System.out.println("鏄剧ず鏌辩姸鍥撅紒"); } } diff --git a/src/com/duwei/designpattern/simplefictory/LineChart.java b/src/com/duwei/designpattern/simplefictory/LineChart.java index cc66b54..a6a7f36 100644 --- a/src/com/duwei/designpattern/simplefictory/LineChart.java +++ b/src/com/duwei/designpattern/simplefictory/LineChart.java @@ -1,12 +1,12 @@ package com.duwei.designpattern.simplefictory; -//折线图类:具体产品类 +//鎶樼嚎鍥剧被锛氬叿浣撲骇鍝佺被 class LineChart implements Chart { public LineChart() { - System.out.println("创建折线图!"); + System.out.println("鍒涘缓鎶樼嚎鍥撅紒"); } public void display() { - System.out.println("显示折线图!"); + System.out.println("鏄剧ず鎶樼嚎鍥撅紒"); } } \ No newline at end of file diff --git a/src/com/duwei/designpattern/simplefictory/PieChart.java b/src/com/duwei/designpattern/simplefictory/PieChart.java index 8d48e82..898f654 100644 --- a/src/com/duwei/designpattern/simplefictory/PieChart.java +++ b/src/com/duwei/designpattern/simplefictory/PieChart.java @@ -1,12 +1,12 @@ package com.duwei.designpattern.simplefictory; -//饼状图类:具体产品类 +//楗肩姸鍥剧被锛氬叿浣撲骇鍝佺被 class PieChart implements Chart { public PieChart() { - System.out.println("创建饼状图!"); + System.out.println("鍒涘缓楗肩姸鍥撅紒"); } public void display() { - System.out.println("显示饼状图!"); + System.out.println("鏄剧ず楗肩姸鍥撅紒"); } } \ No newline at end of file diff --git a/src/com/duwei/designpattern/singleton/HungryMan.java b/src/com/duwei/designpattern/singleton/HungryMan.java index 1cd4a4c..8dd2f1c 100644 --- a/src/com/duwei/designpattern/singleton/HungryMan.java +++ b/src/com/duwei/designpattern/singleton/HungryMan.java @@ -2,7 +2,7 @@ public class HungryMan { - private static HungryMan instance = new HungryMan(); + private static final HungryMan instance = new HungryMan(); public static HungryMan getInstance(){ return instance; diff --git a/src/com/duwei/designpattern/singleton/LazyMan.java b/src/com/duwei/designpattern/singleton/LazyMan.java index 08a3c55..cc46398 100644 --- a/src/com/duwei/designpattern/singleton/LazyMan.java +++ b/src/com/duwei/designpattern/singleton/LazyMan.java @@ -1,7 +1,7 @@ package com.duwei.designpattern.singleton; public class LazyMan { - private static LazyMan instance = null; // 延迟加载 + private static LazyMan instance = null; // 寤惰繜鍔犺浇 private LazyMan() { } diff --git a/src/com/duwei/designpattern/singleton/StaticInnerSingleton.java b/src/com/duwei/designpattern/singleton/StaticInnerSingleton.java index a9ee7a8..d0d18e9 100644 --- a/src/com/duwei/designpattern/singleton/StaticInnerSingleton.java +++ b/src/com/duwei/designpattern/singleton/StaticInnerSingleton.java @@ -4,13 +4,13 @@ class StaticInnerSingleton { private StaticInnerSingleton() {} private static class HolderClass { - //静态实例属于类,所有HolderClass对象共享一个Singleton实例, - //保证线程安全 + //闈欐佸疄渚嬪睘浜庣被锛屾墍鏈塇olderClass瀵硅薄鍏变韩涓涓猄ingleton瀹炰緥锛 + //淇濊瘉绾跨▼瀹夊叏 private final static StaticInnerSingleton instance = new StaticInnerSingleton(); } public static StaticInnerSingleton getInstance() { return HolderClass.instance; - //初始化类时才初始化外部类对象:懒加载 + //鍒濆鍖栫被鏃舵墠鍒濆鍖栧閮ㄧ被瀵硅薄锛氭噿鍔犺浇 } } diff --git a/src/com/duwei/designpattern/state/Client.java b/src/com/duwei/designpattern/state/Client.java index 2988335..3b159b7 100644 --- a/src/com/duwei/designpattern/state/Client.java +++ b/src/com/duwei/designpattern/state/Client.java @@ -1,9 +1,9 @@ package com.duwei.designpattern.state; /** - * 状态模式的定义: - * 当一个对象内在状态改变时允许其改变行为 - * 状态的改变引起了行为的改变 - * @author 杜伟 + * 鐘舵佹ā寮忕殑瀹氫箟锛 + * 褰撲竴涓璞″唴鍦ㄧ姸鎬佹敼鍙樻椂鍏佽鍏舵敼鍙樿涓 + * 鐘舵佺殑鏀瑰彉寮曡捣浜嗚涓虹殑鏀瑰彉 + * @author 鏉滀紵 * */ public class Client { diff --git a/src/com/duwei/designpattern/state/ClosingState.java b/src/com/duwei/designpattern/state/ClosingState.java index 9827642..db1a28d 100644 --- a/src/com/duwei/designpattern/state/ClosingState.java +++ b/src/com/duwei/designpattern/state/ClosingState.java @@ -10,7 +10,7 @@ public void open() { @Override public void close() { - System.out.println("电梯门关闭。。。"); + System.out.println("鐢垫闂ㄥ叧闂傘傘"); } @Override diff --git a/src/com/duwei/designpattern/state/Context.java b/src/com/duwei/designpattern/state/Context.java index cc48055..a5d370b 100644 --- a/src/com/duwei/designpattern/state/Context.java +++ b/src/com/duwei/designpattern/state/Context.java @@ -7,7 +7,7 @@ public class Context { public static final RunningState RUNNING_STATE = new RunningState(); public static final StoppingState STOPPING_STATE = new StoppingState(); - /**内部状态的控制*/ + /**鍐呴儴鐘舵佺殑鎺у埗*/ private LiftState liftState; public LiftState getLiftState(){ diff --git a/src/com/duwei/designpattern/state/LiftState.java b/src/com/duwei/designpattern/state/LiftState.java index d5d45d0..b334db1 100644 --- a/src/com/duwei/designpattern/state/LiftState.java +++ b/src/com/duwei/designpattern/state/LiftState.java @@ -1,7 +1,7 @@ package com.duwei.designpattern.state; /** - * 电梯状态抽象类 - * @author 杜伟 + * 鐢垫鐘舵佹娊璞$被 + * @author 鏉滀紵 */ public abstract class LiftState { protected Context context; diff --git a/src/com/duwei/designpattern/state/OpeningState.java b/src/com/duwei/designpattern/state/OpeningState.java index bbd9f22..348c9f2 100644 --- a/src/com/duwei/designpattern/state/OpeningState.java +++ b/src/com/duwei/designpattern/state/OpeningState.java @@ -4,7 +4,7 @@ public class OpeningState extends LiftState{ @Override public void open() { - System.out.println("电梯门开了。。。"); + System.out.println("鐢垫闂ㄥ紑浜嗐傘傘"); } @Override diff --git a/src/com/duwei/designpattern/state/RunningState.java b/src/com/duwei/designpattern/state/RunningState.java index e650f46..a87f88e 100644 --- a/src/com/duwei/designpattern/state/RunningState.java +++ b/src/com/duwei/designpattern/state/RunningState.java @@ -12,7 +12,7 @@ public void close() { @Override public void run() { - System.out.println("电梯上下运行。。。"); + System.out.println("鐢垫涓婁笅杩愯銆傘傘"); } diff --git a/src/com/duwei/designpattern/state/StoppingState.java b/src/com/duwei/designpattern/state/StoppingState.java index 886d37b..5bc7695 100644 --- a/src/com/duwei/designpattern/state/StoppingState.java +++ b/src/com/duwei/designpattern/state/StoppingState.java @@ -22,7 +22,7 @@ public void run() { @Override public void stop() { - System.out.println("电梯停止了。。。"); + System.out.println("鐢垫鍋滄浜嗐傘傘"); } } diff --git a/src/com/duwei/designpattern/state2/Account.java b/src/com/duwei/designpattern/state2/Account.java index d4e4b00..4e72c42 100644 --- a/src/com/duwei/designpattern/state2/Account.java +++ b/src/com/duwei/designpattern/state2/Account.java @@ -1,15 +1,15 @@ package com.duwei.designpattern.state2; -//银行账户:环境类 +//閾惰璐︽埛锛氱幆澧冪被 class Account { - private AccountState state; //维持一个对抽象状态对象的引用 - private String owner; //开户名 - private double balance = 0; //账户余额 + private AccountState state; //缁存寔涓涓鎶借薄鐘舵佸璞$殑寮曠敤 + private String owner; //寮鎴峰悕 + private double balance = 0; //璐︽埛浣欓 public Account(String owner,double init) { this.owner = owner; this.balance = balance; - this.state = new NormalState(this); //设置初始状态 - System.out.println(this.owner + "开户,初始金额为" + init); + this.state = new NormalState(this); //璁剧疆鍒濆鐘舵 + System.out.println(this.owner + "寮鎴凤紝鍒濆閲戦涓" + init); System.out.println("---------------------------------------------"); } @@ -26,23 +26,23 @@ public void setState(AccountState state) { } public void deposit(double amount) { - System.out.println(this.owner + "存款" + amount); - state.deposit(amount); //调用状态对象的deposit()方法 - System.out.println("现在余额为"+ this.balance); - System.out.println("现在帐户状态为"+ this.state.getClass().getName()); + System.out.println(this.owner + "瀛樻" + amount); + state.deposit(amount); //璋冪敤鐘舵佸璞$殑deposit()鏂规硶 + System.out.println("鐜板湪浣欓涓"+ this.balance); + System.out.println("鐜板湪甯愭埛鐘舵佷负"+ this.state.getClass().getName()); System.out.println("---------------------------------------------"); } public void withdraw(double amount) { - System.out.println(this.owner + "取款" + amount); - state.withdraw(amount); //调用状态对象的withdraw()方法 - System.out.println("现在余额为"+ this.balance); - System.out.println("现在帐户状态为"+ this. state.getClass().getName()); + System.out.println(this.owner + "鍙栨" + amount); + state.withdraw(amount); //璋冪敤鐘舵佸璞$殑withdraw()鏂规硶 + System.out.println("鐜板湪浣欓涓"+ this.balance); + System.out.println("鐜板湪甯愭埛鐘舵佷负"+ this. state.getClass().getName()); System.out.println("---------------------------------------------"); } public void computeInterest() { - state.computeInterest(); //调用状态对象的computeInterest()方法 + state.computeInterest(); //璋冪敤鐘舵佸璞$殑computeInterest()鏂规硶 } } diff --git a/src/com/duwei/designpattern/state2/AccountState.java b/src/com/duwei/designpattern/state2/AccountState.java index 19de964..9912f0d 100644 --- a/src/com/duwei/designpattern/state2/AccountState.java +++ b/src/com/duwei/designpattern/state2/AccountState.java @@ -1,6 +1,6 @@ package com.duwei.designpattern.state2; -//抽象状态类 +//鎶借薄鐘舵佺被 abstract class AccountState { protected Account acc; public abstract void deposit(double amount); diff --git a/src/com/duwei/designpattern/state2/Client.java b/src/com/duwei/designpattern/state2/Client.java index ecf432d..1050e16 100644 --- a/src/com/duwei/designpattern/state2/Client.java +++ b/src/com/duwei/designpattern/state2/Client.java @@ -2,7 +2,7 @@ class Client { public static void main(String args[]) { - Account acc = new Account("段誉",0.0); + Account acc = new Account("娈佃獕",0.0); acc.deposit(1000); acc.withdraw(2000); acc.deposit(3000); diff --git a/src/com/duwei/designpattern/state2/ConcreteState.java b/src/com/duwei/designpattern/state2/ConcreteState.java deleted file mode 100644 index ba1bf6b..0000000 --- a/src/com/duwei/designpattern/state2/ConcreteState.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.duwei.designpattern.state2; - -class ConcreteState extends State { - public void handle() { - //方法具体实现代码 - } -} diff --git a/src/com/duwei/designpattern/state2/Context.java b/src/com/duwei/designpattern/state2/Context.java deleted file mode 100644 index 15e6a3f..0000000 --- a/src/com/duwei/designpattern/state2/Context.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.duwei.designpattern.state2; - -public class Context { - - private State state; // 维持一个对抽象状态对象的引用 - private int value; // 其他属性值,该属性值的变化可能会导致对象状态发生变化 - - // 设置状态对象 - public void setState(State state) { - this.state = state; - } - - public void request() { - // 其他代码 - state.handle(); // 调用状态对象的业务方法 - // 其他代码 - } -} diff --git a/src/com/duwei/designpattern/state2/NomalState.java b/src/com/duwei/designpattern/state2/NomalState.java deleted file mode 100644 index 04c0c75..0000000 --- a/src/com/duwei/designpattern/state2/NomalState.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.duwei.designpattern.state2; - -//正常状态:具体状态类 -class NormalState extends AccountState { - public NormalState(Account acc) { - this.acc = acc; - } - -public NormalState(AccountState state) { - this.acc = state.acc; - } - - public void deposit(double amount) { - acc.setBalance(acc.getBalance() + amount); - stateCheck(); - } - - public void withdraw(double amount) { - acc.setBalance(acc.getBalance() - amount); - stateCheck(); - } - - public void computeInterest() - { - System.out.println("正常状态,无须支付利息!"); - } - - //状态转换 - public void stateCheck() { - if (acc.getBalance() > -2000 && acc.getBalance() <= 0) { - acc.setState(new OverdraftState(this)); - } - else if (acc.getBalance() == -2000) { - acc.setState(new RestrictedState(this)); - } - else if (acc.getBalance() < -2000) { - System.out.println("操作受限!"); - } - } -} diff --git a/src/com/duwei/designpattern/state2/NormalState.java b/src/com/duwei/designpattern/state2/NormalState.java new file mode 100644 index 0000000..ed2c390 --- /dev/null +++ b/src/com/duwei/designpattern/state2/NormalState.java @@ -0,0 +1,37 @@ +package com.duwei.designpattern.state2; + +//姝e父鐘舵侊細鍏蜂綋鐘舵佺被 +class NormalState extends AccountState { + public NormalState(Account acc) { + this.acc = acc; + } + + public NormalState(AccountState state) { + this.acc = state.acc; + } + + public void deposit(double amount) { + acc.setBalance(acc.getBalance() + amount); + stateCheck(); + } + + public void withdraw(double amount) { + acc.setBalance(acc.getBalance() - amount); + stateCheck(); + } + + public void computeInterest() { + System.out.println("姝e父鐘舵侊紝鏃犻』鏀粯鍒╂伅锛"); + } + + //鐘舵佽浆鎹 + public void stateCheck() { + if (acc.getBalance() > -2000 && acc.getBalance() <= 0) { + acc.setState(new OverdraftState(this)); + } else if (acc.getBalance() == -2000) { + acc.setState(new RestrictedState(this)); + } else if (acc.getBalance() < -2000) { + System.out.println("鎿嶄綔鍙楅檺锛"); + } + } +} diff --git a/src/com/duwei/designpattern/state2/OverdraftState.java b/src/com/duwei/designpattern/state2/OverdraftState.java index 35fbfbb..1d10068 100644 --- a/src/com/duwei/designpattern/state2/OverdraftState.java +++ b/src/com/duwei/designpattern/state2/OverdraftState.java @@ -1,6 +1,6 @@ package com.duwei.designpattern.state2; -//透支状态:具体状态类 +//閫忔敮鐘舵侊細鍏蜂綋鐘舵佺被 class OverdraftState extends AccountState { public OverdraftState(AccountState state) { @@ -18,10 +18,10 @@ public void withdraw(double amount) { } public void computeInterest() { - System.out.println("计算利息!"); + System.out.println("璁$畻鍒╂伅锛"); } - //状态转换 + //鐘舵佽浆鎹 public void stateCheck() { if (acc.getBalance() > 0) { acc.setState(new NormalState(this)); @@ -30,7 +30,7 @@ else if (acc.getBalance() == -2000) { acc.setState(new RestrictedState(this)); } else if (acc.getBalance() < -2000) { - System.out.println("操作受限!"); + System.out.println("鎿嶄綔鍙楅檺锛"); } } } diff --git a/src/com/duwei/designpattern/state2/RestrictedState.java b/src/com/duwei/designpattern/state2/RestrictedState.java index 882c291..bd9ee47 100644 --- a/src/com/duwei/designpattern/state2/RestrictedState.java +++ b/src/com/duwei/designpattern/state2/RestrictedState.java @@ -1,6 +1,6 @@ package com.duwei.designpattern.state2; -//受限状态:具体状态类 +//鍙楅檺鐘舵侊細鍏蜂綋鐘舵佺被 class RestrictedState extends AccountState { public RestrictedState(AccountState state) { this.acc = state.acc; @@ -12,14 +12,14 @@ public void deposit(double amount) { } public void withdraw(double amount) { - System.out.println("帐号受限,取款失败"); + System.out.println("甯愬彿鍙楅檺锛屽彇娆惧け璐"); } public void computeInterest() { - System.out.println("计算利息!"); + System.out.println("璁$畻鍒╂伅锛"); } - //状态转换 + //鐘舵佽浆鎹 public void stateCheck() { if(acc.getBalance() > 0) { acc.setState(new NormalState(this)); diff --git a/src/com/duwei/designpattern/state2/State.java b/src/com/duwei/designpattern/state2/State.java deleted file mode 100644 index d10bafb..0000000 --- a/src/com/duwei/designpattern/state2/State.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.duwei.designpattern.state2; - -public abstract class State { - public abstract void handle(); - -} diff --git a/src/com/duwei/file/FileOprator.java b/src/com/duwei/file/FileOprator.java index 7277a19..d4add0f 100644 --- a/src/com/duwei/file/FileOprator.java +++ b/src/com/duwei/file/FileOprator.java @@ -7,9 +7,9 @@ public class FileOprator { /** - * 读取文件内容到字节数组并返回 - * @param filePath 文件路径 - * @return 文件的字节数组 + * 璇诲彇鏂囦欢鍐呭鍒板瓧鑺傛暟缁勫苟杩斿洖 + * @param filePath 鏂囦欢璺緞 + * @return 鏂囦欢鐨勫瓧鑺傛暟缁 * @throws IOException */ public static byte[] getByteFromFile(String filePath) throws IOException{ @@ -24,12 +24,12 @@ public static byte[] getByteFromFile(String filePath) throws IOException{ FileInputStream in = new FileInputStream(file); int offset = 0; - int numRead = 0; //分段读入缓冲字节数组 + int numRead = 0; //鍒嗘璇诲叆缂撳啿瀛楄妭鏁扮粍 while (offset < b.length && (numRead = in.read(b, offset, b.length - offset)) >= 0) { offset += numRead; } - // 确保所有数据均被读取 + // 纭繚鎵鏈夋暟鎹潎琚鍙 if (offset != b.length) { throw new IOException("Could not completely read file " + file.getName()); } diff --git a/src/com/duwei/file/MethodInClassFile.java b/src/com/duwei/file/MethodInClassFile.java new file mode 100644 index 0000000..8734b0c --- /dev/null +++ b/src/com/duwei/file/MethodInClassFile.java @@ -0,0 +1,21 @@ +package com.duwei.file; + +import java.io.File; + +public class MethodInClassFile { + + public static void main(String[] args) { +// File fil = new File("D:\\123.txt"); +// String name = fil.getName(); +// System.out.println("file name = " + name); +// File newFile = new File("D:\\123.3"); +// if (fil.renameTo(newFile)) { +// System.out.println("rename success"); +// } else { +// System.out.println("rename fail"); +// } + + System.out.println(0/5); + } + +} diff --git a/src/com/duwei/generic/GenericFunction.java b/src/com/duwei/generic/GenericFunction.java new file mode 100644 index 0000000..50e9ef3 --- /dev/null +++ b/src/com/duwei/generic/GenericFunction.java @@ -0,0 +1,16 @@ +package com.duwei.generic; + +/** + * 娉涘瀷鏂规硶 + */ +public class GenericFunction { + + public static void main(String[] args) { + + } + + public T gf(Class t) throws IllegalAccessException, InstantiationException { + return t.newInstance(); + } + +} diff --git a/src/com/duwei/lintcode/DigitalCountes.java b/src/com/duwei/lintcode/DigitalCountes.java new file mode 100644 index 0000000..5a190c1 --- /dev/null +++ b/src/com/duwei/lintcode/DigitalCountes.java @@ -0,0 +1,28 @@ +package com.duwei.lintcode; + +/** + * 璁$畻鏁板瓧k鍦0鍒皀涓殑鍑虹幇鐨勬鏁帮紝k鍙兘鏄0~9鐨勪竴涓 + */ +public class DigitalCountes { + + public int digitCounts(int k, int n) { + // write your code here + int num = 0; + while(n >= 0){ + int m = n; + if(m == 0 && k ==0){ + num++; + }else{ + while(m != 0){ + if(m%10 == k){ + num++; + } + m = m/10; + } + } + n--; + } + return num; + } + +} diff --git a/src/com/duwei/lintcode/HowManyZero.java b/src/com/duwei/lintcode/HowManyZero.java new file mode 100644 index 0000000..86a6afb --- /dev/null +++ b/src/com/duwei/lintcode/HowManyZero.java @@ -0,0 +1,34 @@ +package com.duwei.lintcode; + +/** + * 璁捐涓涓畻娉曪紝璁$畻鍑簄闃朵箻涓熬閮ㄩ浂鐨勪釜鏁 + *

+ * 鎮ㄥ湪鐪熷疄鐨勯潰璇曚腑鏄惁閬囧埌杩囪繖涓锛 + * 鏍蜂緥 + * 11! = 39916800锛屽洜姝ゅ簲璇ヨ繑鍥 2 + */ +public class HowManyZero { + + public static void main(String[] args) { + new HowManyZero().trailingZeros(11); + } + + + public long trailingZeros(long n) { + // write your code here, try to do it without arithmetic operators. + long m = n+1; + int sum = 1; + while (m-- > 1) { + System.out.println(m); + sum *= m; + } + System.out.println(sum); + int num = 0; + while (sum % 10 == 0) { + sum = sum/10; + num++; + } + System.out.println(num); + return num; + } +} diff --git a/src/com/duwei/lintcode/LowCase2Upcase.java b/src/com/duwei/lintcode/LowCase2Upcase.java new file mode 100644 index 0000000..d646fa9 --- /dev/null +++ b/src/com/duwei/lintcode/LowCase2Upcase.java @@ -0,0 +1,15 @@ +package com.duwei.lintcode; + +public class LowCase2Upcase { + + + public static void main(String[] args) { + + char s = 'a'; + String str = String.valueOf(s); + + String up = str.toUpperCase(); + up.charAt(0); + } + +} diff --git a/src/com/duwei/lintcode/MaxNodeInBinaryTree.java b/src/com/duwei/lintcode/MaxNodeInBinaryTree.java new file mode 100644 index 0000000..48217a1 --- /dev/null +++ b/src/com/duwei/lintcode/MaxNodeInBinaryTree.java @@ -0,0 +1,44 @@ +package com.duwei.lintcode; + + +import java.util.List; + +/** + * 杩斿洖浜屽弶鏍戠殑鏈澶ц妭鐐 + */ +public class MaxNodeInBinaryTree { + + TreeNode treeNode = new TreeNode(-100000);//鍒濆鍊艰缃瀬灏 + + public TreeNode maxNode(TreeNode root) { + + if (root == null) { + return null; + } + if (root.value > treeNode.value) { + treeNode = root; + } + + if (root.left != null) { + maxNode(root.left); + } + + if (root.right != null) { + maxNode(root.right); + } + + return treeNode; + } + + private static class TreeNode { + public int value; + public TreeNode left, right; + + public TreeNode(int value) { + this.value = value; + this.left = this.right = null; + } + } + + +} diff --git a/src/com/duwei/lintcode/MergeNum.java b/src/com/duwei/lintcode/MergeNum.java new file mode 100644 index 0000000..d47909d --- /dev/null +++ b/src/com/duwei/lintcode/MergeNum.java @@ -0,0 +1,40 @@ +package com.duwei.lintcode; + +import java.util.PriorityQueue; + +/** + * LintCode:791 + * 缁欏嚭n涓暟锛岀幇鍦ㄨ灏嗚繖n涓暟鍚堝苟鎴愪竴涓暟锛屾瘡娆″彧鑳介夋嫨涓や釜鏁癮,b鍚堝苟锛 + * 姣忔鍚堝苟闇瑕佹秷鑰梐+b鐨勮兘閲忥紝杈撳嚭灏嗚繖n涓暟鍚堝苟鎴愪竴涓暟鍚庢秷鑰楃殑鏈灏忚兘閲忋 + */ +public class MergeNum { + + public int mergeNum(int[] nums) { + PriorityQueue mHeap = new PriorityQueue<>();//灏忔牴鍫 + int value = 0; + + for (int num : nums) {//鍏ㄩ儴add杩涘幓鏋勯犲爢 + mHeap.add(num); + } + + while (mHeap.size() > 1) { + int num1 = mHeap.remove(); + int num2 = mHeap.remove(); + int afterAdd = num1 + num2; + value += afterAdd; + mHeap.add(afterAdd); + } + + return value; + } + + public static void main(String[] args) { + int[] a = {1, 2, 3, 4}; + + MergeNum mergeNum = new MergeNum(); + System.out.print(mergeNum.mergeNum(a)); + + } + + +} diff --git a/src/com/duwei/lintcode/PlusAb.java b/src/com/duwei/lintcode/PlusAb.java new file mode 100644 index 0000000..cd355a2 --- /dev/null +++ b/src/com/duwei/lintcode/PlusAb.java @@ -0,0 +1,28 @@ +package com.duwei.lintcode; + +/** + * 涓嶄娇鐢+杩愮畻绗﹁绠楀拰 + */ +public class PlusAb { + + public int add(int a, int b) { + if ((a & b) == 0) {//鏃犺繘浣嶆儏鍐 + return a | b; + } + + int d = a ^ b; + int c = (a & b) << 1;//杩涗綅 + + while ((d & c) != 0){ + c = c<<1; + } + + return c; + } + + + public static void main(String[] args) { + System.out.print(new PlusAb().add(1,1)); + } + +} diff --git a/src/com/duwei/lintcode/ReversNum.java b/src/com/duwei/lintcode/ReversNum.java new file mode 100644 index 0000000..a1b4d2f --- /dev/null +++ b/src/com/duwei/lintcode/ReversNum.java @@ -0,0 +1,20 @@ +package com.duwei.lintcode; + + +/** + * 缈昏浆涓涓笁浣嶆暟鐨勬暣鏁 + */ +public class ReversNum { + public static void main(String[] args) { + + } + + + public int reversNum(int num){ + + + + return 0; + } + +} diff --git a/src/com/duwei/multythread/FileSearch2.java b/src/com/duwei/multythread/FileSearch2.java index 72d6f24..2937a65 100644 --- a/src/com/duwei/multythread/FileSearch2.java +++ b/src/com/duwei/multythread/FileSearch2.java @@ -50,8 +50,7 @@ public List call() throws Exception { for (File f : files) { if (f.isDirectory()) {// 这是一个目录 Callable> runnable = new FileSearch(f, filter);// 有返回值的任务 - FutureTask> task = new FutureTask>( - runnable); + FutureTask> task = new FutureTask>(runnable); results.add(task); service.submit(task); } else if (filter.accept(f.getParentFile(), f.getName())) { diff --git a/src/com/duwei/multythread/ProducerConsumerInJava.java b/src/com/duwei/multythread/ProducerConsumerInJava.java index 9feb204..a66196c 100644 --- a/src/com/duwei/multythread/ProducerConsumerInJava.java +++ b/src/com/duwei/multythread/ProducerConsumerInJava.java @@ -24,12 +24,6 @@ public static void main(String args[]) { } } -/** - * Producer Thread will keep producing values for Consumer - * to consumer. It will use wait() method when Queue is full - * and use notify() method to send notification to Consumer - * Thread. - */ class Producer extends Thread { private Queue queue; private int maxSize; @@ -62,13 +56,6 @@ public void run() { } } -/** - * Consumer Thread will consumer values form shared queue. - * It will also use wait() method to wait if queue is - * empty. It will also use notify method to send - * notification to producer thread after consuming values - * from queue. - */ class Consumer extends Thread { private Queue queue; private int maxSize; diff --git a/src/com/duwei/multythread/AtomicIntegerDemo.java b/src/com/duwei/multythread/atomic/AtomicIntegerDemo.java similarity index 55% rename from src/com/duwei/multythread/AtomicIntegerDemo.java rename to src/com/duwei/multythread/atomic/AtomicIntegerDemo.java index d0df61e..fa8c763 100644 --- a/src/com/duwei/multythread/AtomicIntegerDemo.java +++ b/src/com/duwei/multythread/atomic/AtomicIntegerDemo.java @@ -1,4 +1,4 @@ -package com.duwei.multythread; +package com.duwei.multythread.atomic; import java.util.concurrent.atomic.AtomicInteger; @@ -6,15 +6,15 @@ public class AtomicIntegerDemo { public static void main(String[] args) { AtomicInteger ai = new AtomicInteger(0); - int i1 = ai.get(); + int i1 = ai.get();//鍙栧0 v(i1); - int i2 = ai.getAndSet(5); + int i2 = ai.getAndSet(5);//鍏堝彇鍊煎啀璁惧0 v(i2); - int i3 = ai.get(); + int i3 = ai.get();//鍙栧5 v(i3); - int i4 = ai.getAndIncrement(); + int i4 = ai.getAndIncrement();//鍙栧煎啀鍔5 v(i4); - v(ai.get()); + v(ai.get());//鍙栧6 } static void v(int i) { diff --git a/src/com/duwei/multythread/atomic/AtomicTest.java b/src/com/duwei/multythread/atomic/AtomicTest.java new file mode 100644 index 0000000..5146db5 --- /dev/null +++ b/src/com/duwei/multythread/atomic/AtomicTest.java @@ -0,0 +1,35 @@ +package com.duwei.multythread.atomic; + +import java.util.concurrent.atomic.AtomicInteger; + +/** + * i++ 鍜 ++i 涓嶆弧瓒崇嚎绋嬬殑鍘熷瓙鎬э紝鍙互浣跨敤AtomicInteger鏉ヨ繘琛岀嚎绋嬪畨鍏ㄧ殑++鎿嶄綔 + */ +public class AtomicTest { + + private static AtomicInteger count = new AtomicInteger(0); + private static final int times = Integer.MAX_VALUE; + + public static void main(String[] args) { + + Thread decThread = new DecThread(); + decThread.start(); + + for (int i = 0; i < times; i++) { + count.incrementAndGet(); + } + + // 绛夊緟decThread缁撴潫 + while (decThread.isAlive()) ; + } + + private static class DecThread extends Thread { + + @Override + public void run() { + for (int i = 0; i < times; i++) { + count.decrementAndGet(); + } + } + } +} diff --git a/src/com/duwei/multythread/condition/ConditionDemo.java b/src/com/duwei/multythread/condition/ConditionDemo.java new file mode 100644 index 0000000..8878b09 --- /dev/null +++ b/src/com/duwei/multythread/condition/ConditionDemo.java @@ -0,0 +1,51 @@ +package com.duwei.multythread.condition; + +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +/** + * 姝や緥鐩稿綋浜庣敓浜ц呮秷璐硅呮ā鍨嬶紵 + * 鍒╃敤Local鐨剓@link Lock#lock}鏂规硶鍔犻攣锛寋@link Lock#unlock()}瑙i攣 + * {@link Condition#await()} and {@link Condition#signal()}瀹炵幇瀵瑰搴旈攣鐨勫敜閱 + */ +public class ConditionDemo { + final Lock lock = new ReentrantLock();//閿佸璞 + final Condition writeCondition = lock.newCondition();//鍐欑嚎绋嬫潯浠 + final Condition readCondition = lock.newCondition();//璇荤嚎绋嬫潯浠 + + final Object[] items = new Object[100];//缂撳瓨闃熷垪 + int putptr/*鍐欑储寮*/, takeptr/*璇荤储寮*/, count/*闃熷垪涓瓨鍦ㄧ殑鏁版嵁涓暟*/; + + public void put(Object x) throws InterruptedException { + lock.lock(); + try { + while (count == items.length)//濡傛灉闃熷垪婊′簡 + writeCondition.await();//闃诲鍐欑嚎绋 + items[putptr] = x;//璧嬪 + if (++putptr == items.length) + putptr = 0;//濡傛灉鍐欑储寮曞啓鍒伴槦鍒楃殑鏈鍚庝竴涓綅缃簡锛岄偅涔堢疆涓0 + ++count;//涓暟++ + readCondition.signal();//鍞ら啋璇荤嚎绋 + } finally { + lock.unlock(); + } + } + + public Object take() throws InterruptedException { + lock.lock(); + try { + while (count == 0)//濡傛灉闃熷垪涓虹┖ + readCondition.await();//闃诲璇荤嚎绋 + Object x = items[takeptr];//鍙栧 + if (++takeptr == items.length) + takeptr = 0;//濡傛灉璇荤储寮曡鍒伴槦鍒楃殑鏈鍚庝竴涓綅缃簡锛岄偅涔堢疆涓0 + --count;//涓暟-- + writeCondition.signal();//鍞ら啋鍐欑嚎绋 + return x; + } finally { + lock.unlock(); + } + } + +} diff --git a/src/com/duwei/multythread/interrupt/InterruptDemo.java b/src/com/duwei/multythread/interrupt/InterruptDemo.java index fc2d154..75a946e 100644 --- a/src/com/duwei/multythread/interrupt/InterruptDemo.java +++ b/src/com/duwei/multythread/interrupt/InterruptDemo.java @@ -21,8 +21,7 @@ public class InterruptDemo { public static class TaskQueue { private static final int MAX_TASKS = 1000; - private BlockingQueue queue - = new LinkedBlockingQueue(MAX_TASKS); + private BlockingQueue queue = new LinkedBlockingQueue(MAX_TASKS); public void putTask(Runnable r) throws InterruptedException { queue.put(r); @@ -35,6 +34,7 @@ public Runnable getTask() throws InterruptedException { /** * 002:鍦ㄦ姏鍑哄紓甯镐箣鍓嶈繘琛屾竻鐞嗘搷浣,妯℃嫙鍖归厤鐜╁娓告垙 + * 鎹曡幏娓呯悊鍐嶆姏鍑 */ public static class PlayerMatcher { private PlayerSource players; @@ -115,6 +115,7 @@ public static class PrimeProducer extends Thread { this.queue = queue; } + @Override public void run() { try { BigInteger p = BigInteger.ONE; diff --git a/src/com/duwei/multythread/lock/ReadWriteLockDemo.java b/src/com/duwei/multythread/lock/ReadWriteLockDemo.java new file mode 100644 index 0000000..6f560db --- /dev/null +++ b/src/com/duwei/multythread/lock/ReadWriteLockDemo.java @@ -0,0 +1,63 @@ +package com.duwei.multythread.lock; + +import java.util.Random; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +public class ReadWriteLockDemo { + + public static void main(String[] args) { + final Data data = new Data(); + for (int i = 0; i < 3; i++) { + new Thread(() -> { + for (int j = 0; j < 5; j++) { + data.set(new Random().nextInt(30)); + } + }).start(); + } + for (int i = 0; i < 3; i++) { + new Thread(() -> { + for (int j = 0; j < 5; j++) { + data.get(); + } + }).start(); + } + } + + + + static class Data { + private int data;// 鍏变韩鏁版嵁 + private ReadWriteLock rwl = new ReentrantReadWriteLock(); + public void set(int data) { + rwl.writeLock().lock();// 鍙栧埌鍐欓攣 + try { + System.out.println(Thread.currentThread().getName() + "鍑嗗鍐欏叆鏁版嵁"); + try { + Thread.sleep(20); + } catch (InterruptedException e) { + e.printStackTrace(); + } + this.data = data; + System.out.println(Thread.currentThread().getName() + "鍐欏叆" + this.data); + } finally { + rwl.writeLock().unlock();// 閲婃斁鍐欓攣 + } + } + public void get() { + rwl.readLock().lock();// 鍙栧埌璇婚攣 + try { + System.out.println(Thread.currentThread().getName() + "鍑嗗璇诲彇鏁版嵁"); + try { + Thread.sleep(20); + } catch (InterruptedException e) { + e.printStackTrace(); + } + System.out.println(Thread.currentThread().getName() + "璇诲彇" + this.data); + } finally { + rwl.readLock().unlock();// 閲婃斁璇婚攣 + } + } + } + +} diff --git a/src/com/duwei/multythread/lock/ReentrantLockDemo.java b/src/com/duwei/multythread/lock/ReentrantLockDemo.java index 4d4a1ea..f178515 100644 --- a/src/com/duwei/multythread/lock/ReentrantLockDemo.java +++ b/src/com/duwei/multythread/lock/ReentrantLockDemo.java @@ -2,12 +2,7 @@ import java.util.concurrent.locks.ReentrantLock; /** - * 锟斤拷锟斤拷锟斤拷锟竭程讹拷锟斤拷i锟斤拷锟斤拷++锟斤拷锟斤拷锟斤拷为锟剿憋拷证锟竭程帮拷全锟斤拷 - * 使锟斤拷锟斤拷 ReentrantLock锟斤拷锟斤拷锟矫凤拷锟较匡拷锟皆匡拷锟斤拷锟斤拷 - * 锟斤拷 synchronized锟斤拷龋锟 ReentrantLock锟斤拷锟斤拷微锟斤拷锟斤拷一锟姐。 - * 锟斤拷为锟斤拷锟斤拷锟斤拷finally锟叫斤拷锟叫斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟 finally锟斤拷锟斤拷锟斤拷 - * 锟叫匡拷锟杰达拷锟斤拷锟斤拷锟斤拷斐o拷锟矫伙拷锟斤拷头牛锟斤拷锟絪ynchronized锟斤拷锟斤拷JVM锟斤拷锟酵凤拷锟斤拷锟斤拷 - * @author 锟斤拷伟 + * @author ??? * */ public class ReentrantLockDemo implements Runnable{ @@ -18,7 +13,7 @@ public void run(){ for (int j = 0; j < 10000000; j++){ lock.lock(); try{ - i++; + i++;//杩欎笉鏄師瀛愭搷浣 } finally{ lock.unlock(); diff --git a/src/com/duwei/multythread/threadlocal/ThreadLocalDemo.java b/src/com/duwei/multythread/threadlocal/ThreadLocalDemo.java new file mode 100644 index 0000000..4515595 --- /dev/null +++ b/src/com/duwei/multythread/threadlocal/ThreadLocalDemo.java @@ -0,0 +1,21 @@ +package com.duwei.multythread.threadlocal; + +public class ThreadLocalDemo { + + public static void main(String[] args) { + ThreadLocal mThreadLocal = new ThreadLocal<>(); + mThreadLocal.set(1); + System.out.println(mThreadLocal.get()); + + new Thread("thread-1"){ + @Override + public void run() { + super.run(); + mThreadLocal.set(2); + System.out.println(mThreadLocal.get()); + } + }.start(); + } + + +} diff --git a/src/com/duwei/multythread/util/CountDownLatchDemo.java b/src/com/duwei/multythread/util/CountDownLatchDemo.java new file mode 100644 index 0000000..e97a33b --- /dev/null +++ b/src/com/duwei/multythread/util/CountDownLatchDemo.java @@ -0,0 +1,52 @@ +package com.duwei.multythread.util; + +import java.util.concurrent.CountDownLatch; + +/** + * 浣跨敤CountDownLatch鍙互浣垮叾浠栦换鍔℃墽琛屽畬鍚庡啀鎵ц鎺ヤ笅鏉ョ殑浠g爜锛岀浉褰撲簬璁℃暟 + */ +public class CountDownLatchDemo { + public static void main(String[] args) { + final CountDownLatch latch = new CountDownLatch(2); + new Thread() { + public void run() { + try { + System.out.println("瀛愮嚎绋" + Thread.currentThread().getName() + "姝e湪鎵ц"); + Thread.sleep(3000); + System.out.println("瀛愮嚎绋" + Thread.currentThread().getName() + "鎵ц瀹屾瘯"); + latch.countDown(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + ; + }.start(); + + new Thread() { + public void run() { + try { + System.out.println("瀛愮嚎绋" + Thread.currentThread().getName() + "姝e湪鎵ц"); + Thread.sleep(3000); + System.out.println("瀛愮嚎绋" + Thread.currentThread().getName() + "鎵ц瀹屾瘯"); + latch.countDown(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + ; + }.start(); + + try { + System.out.println("绛夊緟2涓瓙绾跨▼鎵ц瀹屾瘯..."); + latch.await(); + System.out.println("2涓瓙绾跨▼宸茬粡鎵ц瀹屾瘯"); + System.out.println("缁х画鎵ц涓荤嚎绋"); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + + +} diff --git a/src/com/duwei/multythread/util/CyclicBarrierDemo.java b/src/com/duwei/multythread/util/CyclicBarrierDemo.java new file mode 100644 index 0000000..c7bb0bd --- /dev/null +++ b/src/com/duwei/multythread/util/CyclicBarrierDemo.java @@ -0,0 +1,47 @@ +package com.duwei.multythread.util; + +import java.util.concurrent.BrokenBarrierException; +import java.util.concurrent.CyclicBarrier; + +/** + * 瀛楅潰鎰忔濆洖鐜爡鏍忥紝閫氳繃瀹冨彲浠ュ疄鐜拌涓缁勭嚎绋嬬瓑寰呰嚦鏌愪釜鐘舵佷箣鍚庡啀鍏ㄩ儴鍚屾椂鎵ц銆 + * 鍙仛鍥炵幆鏄洜涓哄綋鎵鏈夌瓑寰呯嚎绋嬮兘琚噴鏀句互鍚庯紝CyclicBarrier鍙互琚噸鐢ㄣ + * 鎴戜滑鏆備笖鎶婅繖涓姸鎬佸氨鍙仛barrier锛屽綋璋冪敤await()鏂规硶涔嬪悗锛岀嚎绋嬪氨澶勪簬barrier浜嗐 + * + * http://www.importnew.com/21889.html + */ +public class CyclicBarrierDemo { + + public static void main(String[] args) { + int N = 4; + CyclicBarrier barrier = new CyclicBarrier(N); + for (int i = 0; i < N; i++) + new Writer(barrier).start(); + + System.out.println("..............."); + } + + static class Writer extends Thread { + private CyclicBarrier cyclicBarrier; + + public Writer(CyclicBarrier cyclicBarrier) { + this.cyclicBarrier = cyclicBarrier; + } + + @Override + public void run() { + System.out.println("绾跨▼" + Thread.currentThread().getName() + "姝e湪鍐欏叆鏁版嵁..."); + try { + Thread.sleep(5000); //浠ョ潯鐪犳潵妯℃嫙鍐欏叆鏁版嵁鎿嶄綔 + System.out.println("绾跨▼" + Thread.currentThread().getName() + "鍐欏叆鏁版嵁瀹屾瘯锛岀瓑寰呭叾浠栫嚎绋嬪啓鍏ュ畬姣"); + cyclicBarrier.await(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (BrokenBarrierException e) { + e.printStackTrace(); + } + System.out.println("鎵鏈夌嚎绋嬪啓鍏ュ畬姣曪紝缁х画澶勭悊鍏朵粬浠诲姟..."); + } + } + +} diff --git a/src/com/duwei/multythread/util/SemaphoreDemo.java b/src/com/duwei/multythread/util/SemaphoreDemo.java new file mode 100644 index 0000000..b090294 --- /dev/null +++ b/src/com/duwei/multythread/util/SemaphoreDemo.java @@ -0,0 +1,46 @@ +package com.duwei.multythread.util; + +import java.util.concurrent.Semaphore; + +/** + * Semaphore缈昏瘧鎴愬瓧闈㈡剰鎬濅负 淇″彿閲忥紝Semaphore鍙互鎺у悓鏃惰闂殑绾跨▼涓暟锛 + * 閫氳繃 acquire() 鑾峰彇涓涓鍙紝濡傛灉娌℃湁灏辩瓑寰咃紝鑰 release() 閲婃斁涓涓鍙 + */ +public class SemaphoreDemo { + + /** + * 鍋囪嫢涓涓伐鍘傛湁5鍙版満鍣紝浣嗘槸鏈8涓伐浜猴紝涓鍙版満鍣ㄥ悓鏃跺彧鑳借涓涓伐浜轰娇鐢紝鍙湁浣跨敤瀹屼簡锛 + * 鍏朵粬宸ヤ汉鎵嶈兘缁х画浣跨敤銆傞偅涔堟垜浠氨鍙互閫氳繃Semaphore鏉ュ疄鐜帮細 + * + * @param args + */ + public static void main(String[] args) { + int N = 8; //宸ヤ汉鏁 + Semaphore semaphore = new Semaphore(5); //鏈哄櫒鏁扮洰 + for (int i = 0; i < N; i++) + new Worker(i, semaphore).start(); + } + + static class Worker extends Thread { + private int num; + private Semaphore semaphore; + + public Worker(int num, Semaphore semaphore) { + this.num = num; + this.semaphore = semaphore; + } + + @Override + public void run() { + try { + semaphore.acquire(); + System.out.println("宸ヤ汉" + this.num + "鍗犵敤涓涓満鍣ㄥ湪鐢熶骇..."); + Thread.sleep(2000); + System.out.println("宸ヤ汉" + this.num + "閲婃斁鍑烘満鍣"); + semaphore.release(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } +} diff --git a/src/com/duwei/multythread/util/Tets.java b/src/com/duwei/multythread/util/Tets.java new file mode 100644 index 0000000..a6d450c --- /dev/null +++ b/src/com/duwei/multythread/util/Tets.java @@ -0,0 +1,21 @@ +package com.duwei.multythread.util; + +public class Tets { + public static void main(String[] args) { + + for (int i = 0;i<5 ;i++){ + new Thread(() -> { + try { + Thread.sleep(3000); + System.out.println(Thread.currentThread().getName() + "2222"); + } catch (Exception e) { + + } + }).start(); + } + + System.out.println("..........."); + + } + +} diff --git a/src/com/duwei/reflect/method/MethodFather.java b/src/com/duwei/reflect/method/MethodFather.java new file mode 100644 index 0000000..bca8132 --- /dev/null +++ b/src/com/duwei/reflect/method/MethodFather.java @@ -0,0 +1,17 @@ +package com.duwei.reflect.method; + +public class MethodFather implements MethodInterface{ + @Override + public void MethodInInterface() { + + } + + public void MethodInFatherPublic(){ + + } + + private void MethodInFatherPrivate(){ + + } + +} diff --git a/src/com/duwei/reflect/method/MethodInterface.java b/src/com/duwei/reflect/method/MethodInterface.java new file mode 100644 index 0000000..74cb8e6 --- /dev/null +++ b/src/com/duwei/reflect/method/MethodInterface.java @@ -0,0 +1,6 @@ +package com.duwei.reflect.method; + +public interface MethodInterface { + + public void MethodInInterface(); +} diff --git a/src/com/duwei/reflect/method/MethodVsDeclaredMethod.java b/src/com/duwei/reflect/method/MethodVsDeclaredMethod.java new file mode 100644 index 0000000..a9cffa5 --- /dev/null +++ b/src/com/duwei/reflect/method/MethodVsDeclaredMethod.java @@ -0,0 +1,66 @@ +package com.duwei.reflect.method; + +import java.lang.reflect.Method; + +/** + * 婕旂ず浜哻lazz.getMethods();鍜宑lazz.getDeclaredMethods();鐨勫尯鍒 + * getMethods 鍙兘鎷垮埌public鏂规硶锛堝寘鎷户鎵跨殑绫绘垨鎺ュ彛鐨勬柟娉曪級 + * getDeclaredMethods 鎷垮埌绫绘垨鎺ュ彛澹版槑鐨勬墍鏈夋柟娉曪紝鍖呮嫭鍏叡銆佷繚鎶ゃ + * 榛樿锛堝寘锛夎闂拰绉佹湁鏂规硶锛屼絾涓嶅寘鎷户鎵跨殑鏂规硶銆 + */ + +public class MethodVsDeclaredMethod extends MethodFather implements Runnable { + + public static void main(String[] args) { + + Class clazz = MethodVsDeclaredMethod.class; + + Method[] methods = clazz.getMethods(); + + Method[] declaredMethods = clazz.getDeclaredMethods(); + + for (Method method : methods) { + System.out.println(method.getName()); + /** + * main + *MethodInInterface + *MethodInFatherPublic + *wait + *wait + *wait + *equals + *toString + *hashCode + *getClass + *notify + *notifyAll + */ + } + + System.out.println("---------------"); + + for (Method method : declaredMethods) { + System.out.println(method.getName()); + /** + * main + * run + * methodDemoPrivate + * methodDemoPublic + */ + } + + } + + private void methodDemoPrivate() { + + } + + public void methodDemoPublic() { + + } + + @Override + public void run() { + + } +} diff --git a/src/com/duwei/thinkingjava/generictype/Erased.java b/src/com/duwei/thinkingjava/generictype/Erased.java index 53c7026..ecce2d1 100644 --- a/src/com/duwei/thinkingjava/generictype/Erased.java +++ b/src/com/duwei/thinkingjava/generictype/Erased.java @@ -3,12 +3,15 @@ import java.util.ArrayList; import java.util.Arrays; +/** + * 娉涘瀷鎿﹂櫎锛氬彧鏈夌紪璇戞湡鏈夋晥 + */ public class Erased { public static void main(String[] args) { Class clazz0 = null; try { - clazz0 =Class.forName("com.duwei.thinkingjava.generictype.Erased");//必须使用完整的报名 + clazz0 =Class.forName("com.duwei.thinkingjava.generictype.Erased");//use full package name } catch (ClassNotFoundException e) { e.printStackTrace(); } diff --git a/src/com/duwei/thinkingjava/innerclass/ClassInFunction.java b/src/com/duwei/thinkingjava/innerclass/ClassInFunction.java index 89589ca..97de609 100644 --- a/src/com/duwei/thinkingjava/innerclass/ClassInFunction.java +++ b/src/com/duwei/thinkingjava/innerclass/ClassInFunction.java @@ -1,13 +1,16 @@ package com.duwei.thinkingjava.innerclass; +/** + * 婕旂ず鍦ㄦ柟娉曢噷闈㈠0鏄庣被锛 + */ public class ClassInFunction { - //类里面放interface + //绫婚噷闈㈡斁interface interface Destination{ String readLabel(); } - //方法里面有个类 + //鏂规硶閲岄潰鏈変釜绫 public Destination destination(String s){ class pDestination implements Destination{ diff --git a/src/com/duwei/thinkingjava/innerclass/OutterClass.java b/src/com/duwei/thinkingjava/innerclass/OutterClass.java index ab70c4d..b69a856 100644 --- a/src/com/duwei/thinkingjava/innerclass/OutterClass.java +++ b/src/com/duwei/thinkingjava/innerclass/OutterClass.java @@ -1,49 +1,51 @@ package com.duwei.thinkingjava.innerclass; + /** - * 访问非静态内部类的方法 - * 访问外部类的属性 - * @author 杜伟 + * 璁块棶闈為潤鎬佸唴閮ㄧ被鐨勬柟娉 + * 璁块棶澶栭儴绫荤殑灞炴 + * + * @author 鏉滀紵 */ public class OutterClass { - private String name = "duwei"; //私有变量 - public String sex = "man"; //公有变量 - private static int age = 15; //静态变量 - - interface IPrintString{ - String print(); - } + private String name = "duwei"; //绉佹湁鍙橀噺 + public String sex = "man"; //鍏湁鍙橀噺 + private static int age = 15; //闈欐佸彉閲 + + interface IPrintString { + String print(); + } + + public String sayOutter() { //灞閮ㄥ唴閮ㄧ被 + class PrintString implements IPrintString { + @Override + public String print() { + return "Outter"; + } + } + return new PrintString().print(); + } - public String sayOutter() { //局部内部类 - class PrintString implements IPrintString{ - @Override - public String print() { - return "Outter"; - } - } - return new PrintString().print(); - } - - public String sayOutter2(){ - return new IPrintString() { //这是匿名内部类 - @Override - public String print() { - return "Outter2"; - } - }.print(); - } + public String sayOutter2() { + return new IPrintString() { //杩欐槸鍖垮悕鍐呴儴绫 + @Override + public String print() { + return "Outter2"; + } + }.print(); + } - class InnerClass { - //private static String name = "123";//不可以有静态变量 - public void sayInner() { //访问外部类的私有,共有,静态属性 - System.out.println("inner:name="+name+",sex="+sex+",age = "+age); - System.out.println(OutterClass.this.sayOutter()+";匿名内部类:" - +OutterClass.this.sayOutter2());//访问外部类的方法 - } - } + class InnerClass { + //private static String name = "123";//鍐呴儴绫讳笉鍙互鏈夐潤鎬佸彉閲 + public void sayInner() { //璁块棶澶栭儴绫荤殑绉佹湁锛屽叡鏈夛紝闈欐佸睘鎬 + System.out.println("inner锛歯ame=" + name + ",sex=" + sex + ",age = " + age); + System.out.println(OutterClass.this.sayOutter() + ";鍖垮悕鍐呴儴绫伙細" + + OutterClass.this.sayOutter2());//璁块棶澶栭儴绫荤殑鏂规硶 + } + } - public static void main(String[] args) { - OutterClass outter = new OutterClass(); - InnerClass inner = outter.new InnerClass();//内部类对象的初始化方式 - inner.sayInner(); - } + public static void main(String[] args) { + OutterClass outter = new OutterClass(); + InnerClass inner = outter.new InnerClass();//鍐呴儴绫诲璞$殑鍒濆鍖栨柟寮 + inner.sayInner(); + } } diff --git a/src/com/duwei/thinkingjava/innerclass/OutterClassField.java b/src/com/duwei/thinkingjava/innerclass/OutterClassField.java index fb14bab..2bd1734 100644 --- a/src/com/duwei/thinkingjava/innerclass/OutterClassField.java +++ b/src/com/duwei/thinkingjava/innerclass/OutterClassField.java @@ -1,7 +1,7 @@ package com.duwei.thinkingjava.innerclass; /** - * 内部类访问外部类的属性 - * @author 杜伟 + * 鍐呴儴绫昏闂閮ㄧ被鐨勫睘鎬 + * @author 鏉滀紵 */ public class OutterClassField { @@ -12,9 +12,9 @@ public class OutterClassField { class Chinese{ public void say(){ - //内部类访问外部类的私有属性 - System.out.println("内部类访问外部类的私有属性"+new OutterClassField().name); - System.out.println("内部类访问外部类的公有属性"+new OutterClassField().sex); + //鍐呴儴绫昏闂閮ㄧ被鐨勭鏈夊睘鎬 + System.out.println("鍐呴儴绫昏闂閮ㄧ被鐨勭鏈夊睘鎬"+new OutterClassField().name); + System.out.println("鍐呴儴绫昏闂閮ㄧ被鐨勫叕鏈夊睘鎬"+new OutterClassField().sex); } diff --git a/src/com/duwei/thinkingjava/innerclass/PrivateInnerClassTest.java b/src/com/duwei/thinkingjava/innerclass/PrivateInnerClassTest.java index c23ff26..8e6f850 100644 --- a/src/com/duwei/thinkingjava/innerclass/PrivateInnerClassTest.java +++ b/src/com/duwei/thinkingjava/innerclass/PrivateInnerClassTest.java @@ -17,14 +17,14 @@ public int add(int a, int b) { } public void say(){ - System.out.println("x的值"+x);//访问外部类的私有方法 + System.out.println("x鐨勫"+x);//璁块棶澶栭儴绫荤殑绉佹湁鏂规硶 } } public static void main(String[] args) { - Inner f = new PrivateInnerClassTest().new Inner();//可以访问私有内部类 + Inner f = new PrivateInnerClassTest().new Inner();//鍙互璁块棶绉佹湁鍐呴儴绫 System.out.println(f.add(10, 20)); f.say(); diff --git a/src/com/duwei/thinkingjava/innerclass/StaticInnerClassTest.java b/src/com/duwei/thinkingjava/innerclass/StaticInnerClassTest.java index 99700a6..bd769f3 100644 --- a/src/com/duwei/thinkingjava/innerclass/StaticInnerClassTest.java +++ b/src/com/duwei/thinkingjava/innerclass/StaticInnerClassTest.java @@ -1,15 +1,15 @@ package com.duwei.thinkingjava.innerclass; /** - * 静态内部类 - * @author 杜伟 + * 闈欐佸唴閮ㄧ被 + * @author 鏉滀紵 */ public class StaticInnerClassTest { private String name = "StaticInnerClassTest"; private static String name2 = "StaticInnerClassTest2"; - interface InnerClassInterface{ //接口里面定义类 + interface InnerClassInterface{ //鎺ュ彛閲岄潰瀹氫箟绫 void print(); - class TestInnerClassInterface implements InnerClassInterface{//接口里面的类可以实现该接口 + class TestInnerClassInterface implements InnerClassInterface{//鎺ュ彛閲岄潰鐨勭被鍙互瀹炵幇璇ユ帴鍙 @Override public void print() { System.out.println("InnerClassInterface"); @@ -23,7 +23,7 @@ static class InnerClass{ public void say(){ System.out.println("inner="+name); System.out.println("age="+age); - //System.out.println(StaticInnerClassTest.this.name);//内部类先加载了,外部类不可达 + //System.out.println(StaticInnerClassTest.this.name);//鍐呴儴绫诲厛鍔犺浇浜嗭紝澶栭儴绫讳笉鍙揪 } } diff --git a/src/com/duwei/thinkingjava/innerclass/TestInnerClass.java b/src/com/duwei/thinkingjava/innerclass/TestInnerClass.java index aaaa21e..9bc4f3f 100644 --- a/src/com/duwei/thinkingjava/innerclass/TestInnerClass.java +++ b/src/com/duwei/thinkingjava/innerclass/TestInnerClass.java @@ -1,10 +1,9 @@ package com.duwei.thinkingjava.innerclass; -import com.duwei.thinkingjava.reflect.This; public class TestInnerClass { - private Inner inner = this.new Inner();//没 + private Inner inner = this.new Inner(); public void loadInner(){ inner = new Inner(); diff --git a/src/com/duwei/thinkingjava/innerclass/multiextends/ClassOne.java b/src/com/duwei/thinkingjava/innerclass/multiextends/ClassOne.java new file mode 100644 index 0000000..803aa3d --- /dev/null +++ b/src/com/duwei/thinkingjava/innerclass/multiextends/ClassOne.java @@ -0,0 +1,4 @@ +package com.duwei.thinkingjava.innerclass.multiextends; + +public class ClassOne { +} diff --git a/src/com/duwei/thinkingjava/innerclass/multiextends/ClassTwo.java b/src/com/duwei/thinkingjava/innerclass/multiextends/ClassTwo.java new file mode 100644 index 0000000..4dad249 --- /dev/null +++ b/src/com/duwei/thinkingjava/innerclass/multiextends/ClassTwo.java @@ -0,0 +1,4 @@ +package com.duwei.thinkingjava.innerclass.multiextends; + +public class ClassTwo { +} diff --git a/src/com/duwei/thinkingjava/innerclass/multiextends/MultiExtends.java b/src/com/duwei/thinkingjava/innerclass/multiextends/MultiExtends.java new file mode 100644 index 0000000..35e7c40 --- /dev/null +++ b/src/com/duwei/thinkingjava/innerclass/multiextends/MultiExtends.java @@ -0,0 +1,31 @@ +package com.duwei.thinkingjava.innerclass.multiextends; + +/** + * 鍐呴儴绫诲疄鐜板缁ф壙鐨勫師鐞 + */ +public class MultiExtends { + + + private class InnerOne extends ClassOne { + public String getName() { + return "wdw"; + } + } + + private class InnerTwo extends ClassTwo { + public int getAge() { + return 11; + } + } + + + public String getName() { + return new InnerOne().getName(); + } + + public int getAge() { + return new InnerTwo().getAge(); + } + + +} diff --git a/src/com/duwei/thinkingjava/reflect/Other.java b/src/com/duwei/thinkingjava/reflect/Other.java index f5acd2f..d4c621c 100644 --- a/src/com/duwei/thinkingjava/reflect/Other.java +++ b/src/com/duwei/thinkingjava/reflect/Other.java @@ -5,11 +5,11 @@ public class Other extends OtherFather{ static final int AGE = 24; static { - System.out.println("5-->Other被初始化了"); + System.out.println("5-->Other琚垵濮嬪寲浜"); } Other(){ - System.out.println("7-->Other构造函数"); + System.out.println("7-->Other鏋勯犲嚱鏁"); } } diff --git a/src/com/duwei/thinkingjava/reflect/OtherFather.java b/src/com/duwei/thinkingjava/reflect/OtherFather.java index f1a6a05..efa1af0 100644 --- a/src/com/duwei/thinkingjava/reflect/OtherFather.java +++ b/src/com/duwei/thinkingjava/reflect/OtherFather.java @@ -2,9 +2,9 @@ public class OtherFather { static{ - System.out.println("4-->OtherFather 初始化了"); + System.out.println("4-->OtherFather 鍒濆鍖栦簡"); } public OtherFather() { - System.out.println("6-->OtherFather构造函数"); + System.out.println("6-->OtherFather鏋勯犲嚱鏁"); } } diff --git a/src/com/duwei/thinkingjava/reflect/This.java b/src/com/duwei/thinkingjava/reflect/This.java index d106be0..5052e68 100644 --- a/src/com/duwei/thinkingjava/reflect/This.java +++ b/src/com/duwei/thinkingjava/reflect/This.java @@ -1,20 +1,23 @@ package com.duwei.thinkingjava.reflect; +/** + * 姝emo婕旂ず浜嗭紝鐖剁被涓庡瓙绫伙紝闈欐佷唬鐮佸潡锛屾瀯閫犲嚱鏁癿ain鏂规硶绛夌殑鍒濆鍖栧拰鎵ц椤哄簭 + */ public class This { - static Other other;//引用 + static Other other;//寮曠敤 static{ - System.out.println("1-->This被初始化了");//1 + System.out.println("1-->This琚垵濮嬪寲浜");//1 } This(){ - System.out.println("3-->This的构造函数");//3 + System.out.println("3-->This鐨勬瀯閫犲嚱鏁");//3 } public static void main(String[] args) { - System.out.println("2-->main被执行了");//2 + System.out.println("2-->main琚墽琛屼簡");//2 This ths = new This(); - //System.out.println(Other.AGE);//不需要初始化类而调用类的变量-->编译期常量 + //System.out.println(Other.AGE);//涓嶉渶瑕佸垵濮嬪寲绫昏岃皟鐢ㄧ被鐨勫彉閲-->缂栬瘧鏈熷父閲 - //Class clazz = Other.class;//不会进行初始化 - //Class clazz = Class.forName("com.duwei.thinkingjava.reflect.Other");//将进行初始化 - other = new Other();//用到某个类的时候才去加载某个类 + //Class clazz = Other.class;//涓嶄細杩涜鍒濆鍖 + //Class clazz = Class.forName("com.duwei.thinkingjava.reflect.Other");//灏嗚繘琛屽垵濮嬪寲 + other = new Other();//鐢ㄥ埌鏌愪釜绫荤殑鏃跺欐墠鍘诲姞杞芥煇涓被 } } diff --git a/src/com/duwei/thinkingjava/reflect/method/StudentDemo.java b/src/com/duwei/thinkingjava/reflect/method/StudentDemo.java index 0a17c8d..3eafb01 100644 --- a/src/com/duwei/thinkingjava/reflect/method/StudentDemo.java +++ b/src/com/duwei/thinkingjava/reflect/method/StudentDemo.java @@ -65,22 +65,22 @@ public void setAddress(String address) { public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { - StudentDemo sd=new StudentDemo(); + StudentDemo sd=new StudentDemo(); sd.setId(1); - sd.setName("测试invoke"); - sd.setSex("未知"); + sd.setName("myName"); + sd.setSex("male"); sd.setAge("10000"); - sd.setBrithday("19920205"); - sd.setAddress("湖南"); + sd.setBrithday("19930205"); + sd.setAddress("china guangzhou"); Object[] agrs = new Object[]{}; StringBuilder sb = new StringBuilder(); for (Method m : sd.getClass().getMethods()) { if (m.getName().startsWith("get")) { - // System.out.println(m.getName()); + System.out.println(m.getName()); sb.append(" <" + m.getName().substring(3) + ">"); - sb.append(m.invoke(sd,null)); //执行这个方法,参数列表 + sb.append(m.invoke(sd,null)); //执锟斤拷锟斤拷锟斤拷锟斤拷锟,锟斤拷锟斤拷锟叫憋拷 sb.append("\r"); - // System.out.println("---"+m.invoke(sd, args)); + System.out.println("---"+m.invoke(sd, args)); } } System.out.println(sb.toString()); diff --git a/src/com/duwei/thinkingjava/reflect/method/TestInvoke.java b/src/com/duwei/thinkingjava/reflect/method/TestInvoke.java index 9d8900d..a227336 100644 --- a/src/com/duwei/thinkingjava/reflect/method/TestInvoke.java +++ b/src/com/duwei/thinkingjava/reflect/method/TestInvoke.java @@ -4,29 +4,31 @@ import java.lang.reflect.Method; public class TestInvoke { - - public void work(){ - System.out.println("没有参数="); - } - public TestInvoke work(String a,Integer b){ - System.out.println("两个参数="+a+b); - return this; - } - public void work(int b){ - System.out.println("一个参数="+b); - } - - public static void main(String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, NoSuchMethodException, SecurityException { - Class clazz = TestInvoke.class; - - Method noParam = clazz.getMethod("work", new Class[]{}); - Method twoParam = clazz.getMethod("work", new Class[]{String.class,Integer.class}); - Method threeParam = clazz.getMethod("work", new Class[]{int.class}); - - - noParam.invoke(clazz.newInstance(), new Object[]{}); - twoParam.invoke(clazz.newInstance(), new Object[]{"wdw",new Integer(10)}); - threeParam.invoke(clazz.newInstance(), new Object[]{new Integer(10)}); - } + + public void work() { + System.out.println("no Param"); + } + + public TestInvoke work(String a, Integer b) { + System.out.println("two Param=" + a + b); + return this; + } + + public void work(int b) { + System.out.println("one Param=" + b); + } + + public static void main(String[] args) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException, NoSuchMethodException, SecurityException { + Class clazz = TestInvoke.class; + + Method noParam = clazz.getMethod("work", new Class[]{}); + Method twoParam = clazz.getMethod("work", new Class[]{String.class, Integer.class}); + Method threeParam = clazz.getMethod("work", new Class[]{int.class}); + + + noParam.invoke(clazz.newInstance(), new Object[]{}); + twoParam.invoke(clazz.newInstance(), new Object[]{"wdw", new Integer(10)}); + threeParam.invoke(clazz.newInstance(), new Object[]{new Integer(10)}); + } } diff --git a/src/com/duweri/interview/AllTestHere.java b/src/com/duweri/interview/AllTestHere.java index a609a6b..150bdf0 100644 --- a/src/com/duweri/interview/AllTestHere.java +++ b/src/com/duweri/interview/AllTestHere.java @@ -8,9 +8,9 @@ public class AllTestHere { - public static void main(String[] args) { - // AllTestHere.test1(); - // AllTestHere.test2(); + public static void main(String[] args) { +// AllTestHere.test1(); + // AllTestHere.test2(); // AllTestHere.test3(); // System.out.println(AllTestHere.test4()); // AllTestHere.test5(); @@ -18,150 +18,144 @@ public static void main(String[] args) { // AllTestHere.test7(); // AllTestHere.test8(); // AllTestHere.test9(); - AllTestHere.test10(); - } - - public static void test1() { - boolean b = true; - if (b) { - } - for (int i = 0;; i = 3) { - System.out.println(i); - // return; - } - } - /** - * int & Integer的比较 - */ - public static void test2() { - int i = 0; - Integer integer = new Integer(0); - - System.out.println(i == integer);//true - System.out.println(integer.equals(i));//true - } - /** - * Collection相关方法 - */ - public static void test3() { - int array[] = { 112, 111, 23, 456, 231 }; - // double[] arr = {}; - List list = new ArrayList(); - - for (int i = 0; i < array.length; i++) { - list.add(new Integer(array[i])); - } - // -------------排序----------------------- - Collections.sort(list); - for (int i = 0; i < array.length; i++) { - System.out.print(list.get(i) + ","); - } - System.out.println(); - // ---------------混排---------------------- - System.out.println("-----混排--------"); - Collections.shuffle(list); - for (int i = 0; i < array.length; i++) { - System.out.print(list.get(i) + ","); - } - System.out.println(); - // -----------------反转-------------------- - System.out.println("-----反转-------"); - Collections.reverse(list); - for (int i = 0; i < array.length; i++) { - System.out.print(list.get(i) + ","); - } - System.out.println(); - // -----------------最小值-------------------- - System.out.println("-----------最小值---------"); - Collections.min(list); - for (int i = 0; i < list.size(); i++) { - System.out.print(list.get(i) + ","); - } - System.out.println(); - // -----------------最大-------------------- - System.out.println("-------最大------"); - Collections.max(list); - for (int i = 0; i < list.size(); i++) { - System.out.print(list.get(i) + ","); - } - - System.out.println(); - // -----------------替换-------------------- - System.out.println("-------替换------"); - Collections.fill(list, 111); - for (int i = 0; i < array.length; i++) { - System.out.print(list.get(i) + ","); - } - - } - /** - * 日期格式化 - */ - public static String test4(){ - SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); - Date curDate = new Date(System.currentTimeMillis());// 获取当前时间 + AllTestHere.test10(); + } + + public static void test1() { + boolean b = true; + if (b) { + } + for (int i = 0; ; i = 3) {//姝诲惊鐜 + System.out.println(i); + // return; + } + } + + /** + * int & Integer鐨勬瘮杈 + */ + public static void test2() { + int i = 0; + Integer integer = new Integer(0); + + System.out.println(i == integer);//true + System.out.println(integer.equals(i));//true + } + + /** + * Collection鐩稿叧鏂规硶 + */ + public static void test3() { + int array[] = {112, 111, 23, 456, 231}; + // double[] arr = {}; + List list = new ArrayList(); + + for (int i = 0; i < array.length; i++) { + list.add(new Integer(array[i])); + } + // -------------鎺掑簭----------------------- + Collections.sort(list); + for (int i = 0; i < array.length; i++) { + System.out.print(list.get(i) + ","); + } + System.out.println(); + // ---------------娣锋帓---------------------- + System.out.println("-----娣锋帓--------"); + Collections.shuffle(list); + for (int i = 0; i < array.length; i++) { + System.out.print(list.get(i) + ","); + } + System.out.println(); + // -----------------鍙嶈浆-------------------- + System.out.println("-----鍙嶈浆-------"); + Collections.reverse(list); + for (int i = 0; i < array.length; i++) { + System.out.print(list.get(i) + ","); + } + System.out.println(); + // -----------------鏈灏忓-------------------- + System.out.println("-----------鏈灏忓---------"); + Collections.min(list); + for (int i = 0; i < list.size(); i++) { + System.out.print(list.get(i) + ","); + } + System.out.println(); + // -----------------鏈澶-------------------- + System.out.println("-------鏈澶------"); + Collections.max(list); + for (int i = 0; i < list.size(); i++) { + System.out.print(list.get(i) + ","); + } + + System.out.println(); + // -----------------鏇挎崲-------------------- + System.out.println("-------鏇挎崲------"); + Collections.fill(list, 111); + for (int i = 0; i < array.length; i++) { + System.out.print(list.get(i) + ","); + } + + } + + /** + * 鏃ユ湡鏍煎紡鍖 + */ + public static String test4() { + SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); + Date curDate = new Date(System.currentTimeMillis());// 鑾峰彇褰撳墠鏃堕棿 return formatter.format(curDate); - } - - public static void test5(){ - Boolean flag = false; - if (flag = true){//这里是赋值不是== - System.out.println("true"); - } - else{ - System.out.println("false"); - } - } - - public static void test6(){ - short a =128; - byte b = (byte)a; - System.out.println("a="+a+"b="+b); - } - - public static void test7(){ - Integer var1 = new Integer(1); - Integer var2 = var1; - - doSomething(var2); - - System.out.println(var1.intValue()); - System.out.println(var1==var2); - } - - private static void doSomething(Integer integer) { - integer = new Integer(2); - } - - public static void test8(){ - try { - System.out.println("try"); - throw new Exception(); - } catch (Exception e) { - System.out.println("catch"); - return; - }finally{ - System.out.println("finally"); - } - } - - public static void test9(){ - String x="fmn"; - x.toUpperCase(); - System.out.println(x); - String y=x.replace('f','F'); - System.out.println(y); - y=y+"wxy"; - System.out.println(y); - } - /** - * i++ && ++i - */ - public static void test10(){ - int i = 0; - System.out.println(i++);//0 - System.out.println(++i);//2 - } - - + } + + public static void test5() { + Boolean flag = false; + if (flag = true) {//杩欓噷鏄祴鍊间笉鏄== + System.out.println("true"); + } else { + System.out.println("false"); + } + } + + public static void test6() { + short a = 128; + byte b = (byte) a; + System.out.println("a=" + a + "b=" + b); + } + + public static void test7() { + Integer var1 = new Integer(1); + Integer var2 = var1; + + doSomething(var2); + + System.out.println(var1.intValue()); + System.out.println(var1 == var2); + } + + private static void doSomething(Integer integer) { + integer = new Integer(2); + } + + + public static void test9() { + String x = "fmn"; + x.toUpperCase(); + System.out.println(x); + String y = x.replace('f', 'F'); + System.out.println(y); + y = y + "wxy"; + System.out.println(y); + } + + /** + * i++ && ++i + */ + public static void test10() { + int i = 0; + int j = 0; + System.out.println(i++);//0 + System.out.println(++i);//2 + System.out.println(++j);//1 + } + + } diff --git a/src/com/duweri/interview/ArrayNumSplit.java b/src/com/duweri/interview/ArrayNumSplit.java new file mode 100644 index 0000000..a439a69 --- /dev/null +++ b/src/com/duweri/interview/ArrayNumSplit.java @@ -0,0 +1,38 @@ +package com.duweri.interview; + +/** + * 鍒嗙鏁扮粍涓殑姝h礋鏁 + */ +public class ArrayNumSplit { + + static int array[] = {1, -5, 2, 6, -7, 5, -4, 7}; + + public static void main(String[] args) { + int i = 0, j = array.length - 1; + while (i < j) { + if (array[i] > 0 && array[j] < 0) { + int temp = array[i]; + array[i] = array[j]; + array[j] = temp; + i++; + j--; + } + + if (array[i] < 0) { + i++; + } + + if (array[j] > 0) { + j--; + } + } + print(array); + } + + private static void print(int[] array) { + for (int i = 0; i < array.length; i++) { + System.out.print(array[i] + ","); + } + } + +} diff --git a/src/com/duweri/interview/BitCompute.java b/src/com/duweri/interview/BitCompute.java index 6d77ad6..b4da3d5 100644 --- a/src/com/duweri/interview/BitCompute.java +++ b/src/com/duweri/interview/BitCompute.java @@ -1,37 +1,50 @@ package com.duweri.interview; + /** - * 位运算Demo - * @author 杜伟 - * + * 浣嶈繍绠桪emo + * + * @author 鏉滀紵 */ public class BitCompute { - public static void main(String[] args) { - //异或 - int a = 8;//1000 - int b = 9;//1001 - System.out.println("a^b = "+(a^b)); - - int x = 15;//01111=1+2+4+8 - int y = 23;//10111=1+2+4+16 - System.out.println("x^y = "+(x^y)); - - //与运算 - System.out.println("x&y = "+(x&y)); - - //或运算 - System.out.println("x|y = "+ (x|y)); - - //左右移运算 - System.out.println("8>>2 = "+(8>>2)); - System.out.println("8<<2 = "+(8<<2)); - - //~ 原码01000放进计算机用补码:01000, - //取反计算:10111(这是补码),输出源码(取反加1,符号位不变):11001 - System.out.println("~ = "+(~8)); - - System.out.println("8>>>2="+(8>>>2)); - - } + public static void main(String[] args) { + //寮傛垨 + int a = 8;//1000 + int b = 9;//1001 + ////////////0001 + System.out.println("a^b = " + (a ^ b)); + + int x = 15;//01111=1+2+4+8 + int y = 23;//10111=1+2+4+16 + /////////////11000=16+8=24 + System.out.println("x^y = " + (x ^ y)); + + //涓庤繍绠 + //int x = 15;//01111=1+2+4+8 + //int y = 23;//10111=1+2+4+16 + ///////////////00111=4+2+1=7 + System.out.println("x&y = " + (x & y)); + + //鎴栬繍绠 + //int x = 15;//01111=1+2+4+8 + //int y = 23;//10111=1+2+4+16 + ///////////////11111=16+8+4+2+1=31 + System.out.println("x|y = " + (x | y)); + + //宸﹀彸绉昏繍绠 + //0000 1000>>0000 0010 + //0000 1000<<0010 0000 + System.out.println("8>>2 = " + (8 >> 2));//2 + System.out.println("8<<2 = " + (8 << 2));//32 + System.out.println("8<<2 = " + (8 << 5));//256 + System.out.println("1<<32 = " + (1 << 32));//1 + + //~ 鍘熺爜01000鏀捐繘璁$畻鏈虹敤琛ョ爜锛01000锛 + //鍙栧弽璁$畻锛10111锛堣繖鏄ˉ鐮侊級锛岃緭鍑烘簮鐮侊紙鍙栧弽鍔1锛岀鍙蜂綅涓嶅彉锛夛細11001 + System.out.println("~ = " + (~8)); + + System.out.println("8>>>2=" + (8 >>> 2)); + + } } diff --git a/src/com/duweri/interview/ByteComput.java b/src/com/duweri/interview/ByteComput.java new file mode 100644 index 0000000..98f0c05 --- /dev/null +++ b/src/com/duweri/interview/ByteComput.java @@ -0,0 +1,10 @@ +package com.duweri.interview; + +public class ByteComput { + + public static void main(String[] args) { + + + } + +} diff --git a/src/com/duweri/interview/DateTest.java b/src/com/duweri/interview/DateTest.java deleted file mode 100644 index 1cb1341..0000000 --- a/src/com/duweri/interview/DateTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.duweri.interview; - -import java.util.Calendar; - -public class DateTest { - - /** - * @param args - */ - public static void main(String[] args) { - // TODO Auto-generated method stub - int y,m,d,h,mi,s,nowsj; - Calendar calendar = Calendar.getInstance(); - y=calendar.get(Calendar.YEAR); - m=calendar.get(Calendar.MONTH); - d=calendar.get(Calendar.DATE); - h=calendar.get(Calendar.HOUR_OF_DAY); - mi=calendar.get(Calendar.MINUTE); - s=calendar.get(Calendar.MINUTE); - nowsj=y*100+m; - System.out.println(y+"-"+m+"-"+d+"-"+h+"-"+nowsj); - //2016-6-21-10-201606 - } - -} diff --git a/src/com/duweri/interview/FinalTest.java b/src/com/duweri/interview/FinalTest.java index d95e451..49b255b 100644 --- a/src/com/duweri/interview/FinalTest.java +++ b/src/com/duweri/interview/FinalTest.java @@ -4,22 +4,31 @@ import java.util.List; public class FinalTest { - - public static void main(String[] args) { - int a = 10; - System.out.println((a>>1)+5); - System.out.println(a>>1); - System.out.println(a<<1); - final List list = new ArrayList<>(10); - System.out.println(list.size()); - for (int i = 0; i < 15; i++) { - list.add(i+""); - } - System.out.println(list.size()); - for (String string : list) { - System.out.println(string); - } - } - + public static final int a = 1; + public static final int d = 1 << 1;//2 + public static final int b = 1 << 2;//4 + public static final int c = 1 << 3;//8 + + + public static void main(String[] args) { + System.out.println("d = " + d + "b = " + b + "c = " + c); + + int a = 10; + System.out.println((a >> 1) + 5); + System.out.println(a >> 1); + System.out.println(a << 1); + final List list = new ArrayList<>(10); + System.out.println(list.size()); + for (int i = 0; i < 15; i++) { + list.add(i + ""); + } + System.out.println(list.size()); + for (String string : list) { + System.out.println(string); + } + + + } + } diff --git a/src/com/duweri/interview/IntegerCache.java b/src/com/duweri/interview/IntegerCache.java index 5df31d8..8fff310 100644 --- a/src/com/duweri/interview/IntegerCache.java +++ b/src/com/duweri/interview/IntegerCache.java @@ -1,9 +1,9 @@ package com.duweri.interview; /** * http://www.importnew.com/18884.html - * @author 杜伟 + * @author 鏉滀紵 * - * 缓存-128---127的值 + * 缂撳瓨-128---127鐨勫 * */ public class IntegerCache { diff --git a/src/com/duweri/interview/Overload.java b/src/com/duweri/interview/Overload.java deleted file mode 100644 index bcc7c84..0000000 --- a/src/com/duweri/interview/Overload.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.duweri.interview; - -public class Overload {//重载不允许只是返回值类型不同 - -// Object x(){ return "abc";} -// String x(){ return "123";} - public static void main(String[] args) { - } - -} diff --git a/src/com/duweri/interview/OverloadVsOverride.java b/src/com/duweri/interview/OverloadVsOverride.java index 8bd16bc..63a6bdf 100644 --- a/src/com/duweri/interview/OverloadVsOverride.java +++ b/src/com/duweri/interview/OverloadVsOverride.java @@ -1,7 +1,7 @@ package com.duweri.interview; /** - * 重载和重写 - * @author 杜伟 + * 閲嶈浇鍜岄噸鍐 + * @author 鏉滀紵 */ public class OverloadVsOverride { @@ -16,10 +16,10 @@ public static void main(String[] args) { OverloadVsOverride o3 = new OverloadVsOverride(); OverloadVsOverride o4 = new OverloadVsOverride(); - if (o1.equals(o2)) {//o1,o2不相等 + if (o1.equals(o2)) {//o1,o2涓嶇浉绛 System.out.println("o1 equals o2"); } - if (o3.equals(o4)) {//O3,O4相等 + if (o3.equals(o4)) {//O3锛孫4鐩哥瓑 System.out.println("o3 equals o4"); } } diff --git a/src/com/duweri/interview/RemoveInList.java b/src/com/duweri/interview/RemoveInList.java new file mode 100644 index 0000000..80f5675 --- /dev/null +++ b/src/com/duweri/interview/RemoveInList.java @@ -0,0 +1,28 @@ +package com.duweri.interview; + +import java.util.ArrayList; +import java.util.List; + +/** + * 鍦╢or寰幆涓垹闄ゅ厓绱犵殑闂锛氬垹闄ゅ厓绱犱細瀵艰嚧鍒楄〃鍚戝墠绉诲姩 + * 1.鍊掔潃閬嶅巻 + * 2.鍙婃椂淇敼i鍊 + * 3.杩唬鍣 + */ +public class RemoveInList { + + public static void main(String[] args) { + List list = new ArrayList<>(); + list.add("1"); + list.add("2"); + list.add("3"); + list.add("4"); + list.add("5"); + list.add("6"); + + for (int i = 0; i < list.size(); i++) { + list.remove("4"); + } + } + +} diff --git a/src/com/duweri/interview/Sort.java b/src/com/duweri/interview/Sort.java index d105d3e..22f6411 100644 --- a/src/com/duweri/interview/Sort.java +++ b/src/com/duweri/interview/Sort.java @@ -20,39 +20,39 @@ public static void display(int[] arr){ } /** - * 插入排序 - * 关键:1、临时变量保存待排序的数字 - * 2、边比较边后移 - * 适用情况:序列基本有序的时候 + * 鎻掑叆鎺掑簭 + * 鍏抽敭锛1銆佷复鏃跺彉閲忎繚瀛樺緟鎺掑簭鐨勬暟瀛 + * 2銆佽竟姣旇緝杈瑰悗绉 + * 閫傜敤鎯呭喌锛氬簭鍒楀熀鏈湁搴忕殑鏃跺 */ public static void insertSort(int[] arr){ for (int i = 1; i < arr.length; i++) { - int temp = arr[i];//临时保存待插入序列 - int j;//下面先保证J大于0再去访问arr[j]!!!! - for (j = i-1;j >= 0 && temp > arr[j] ; j--) {//带插入序列大于当前序列就前移--》从大到小排列 + int temp = arr[i];//涓存椂淇濆瓨寰呮彃鍏ュ簭鍒 + int j;//涓嬮潰鍏堜繚璇丣澶т簬0鍐嶅幓璁块棶arr[j]!!!! + for (j = i-1;j >= 0 && temp > arr[j] ; j--) {//甯︽彃鍏ュ簭鍒楀ぇ浜庡綋鍓嶅簭鍒楀氨鍓嶇Щ--銆嬩粠澶у埌灏忔帓鍒 arr[j+1] = arr[j]; } arr[j+1]=temp; } } /** - * 希尔排序 + * 甯屽皵鎺掑簭 */ public static void shellSort(int[] arr){ - for (int i = arr.length/2; i >= 1; i=i/2) {//子序列的划分 + for (int i = arr.length/2; i >= 1; i=i/2) {//瀛愬簭鍒楃殑鍒掑垎 } } /** - * 冒泡排序 - * 关键:1、外循环标识无序区和有序区 - * 2、内循环每次将一个无序区的数字排到最前面 + * 鍐掓场鎺掑簭 + * 鍏抽敭锛1銆佸寰幆鏍囪瘑鏃犲簭鍖哄拰鏈夊簭鍖 + * 2銆佸唴寰幆姣忔灏嗕竴涓棤搴忓尯鐨勬暟瀛楁帓鍒版渶鍓嶉潰 */ public static void bubbleSort(int[] arr){ - for (int i = 0; i i; j--) {//从最后一个开始遍历 + for (int i = 0; i i; j--) {//浠庢渶鍚庝竴涓紑濮嬮亶鍘 if (arr[j]>arr[j-1]) { int temp = arr[j];//swap arr[j] = arr[j-1]; @@ -63,10 +63,10 @@ public static void bubbleSort(int[] arr){ } /** - * 快速排序 - * 关键: 1、选轴值 - * 2、一次划分 - * 3、递归快排 + * 蹇熸帓搴 + * 鍏抽敭: 1銆侀夎酱鍊 + * 2銆佷竴娆″垝鍒 + * 3銆侀掑綊蹇帓 */ public static void quickSort(int[] arr,int start,int end){ if(start list = new ArrayList<>(); while (true) { - String splitStr = null; // 保留截取的字符串 + String splitStr = null; // 淇濈暀鎴彇鐨勫瓧绗︿覆 int index = temp.indexOf(","); if (index < 0) { break; diff --git a/src/com/duweri/interview/datastructure/BinSearch.java b/src/com/duweri/interview/datastructure/BinSearch.java index 9d7292d..3255108 100644 --- a/src/com/duweri/interview/datastructure/BinSearch.java +++ b/src/com/duweri/interview/datastructure/BinSearch.java @@ -1,25 +1,24 @@ package com.duweri.interview.datastructure; public class BinSearch { - public static void main(String[] args) { - } - - private static int binSearch(int[] r,int n,int k){ - int low = 1; - int high = n; - while(low <= high){ - int mid = (low+high)/2; - if (r[mid] > k) { - high = mid - 1; - }else if (r[mid] < k) { - low = mid+1; - }else{ - return mid; - } - } - return 0; - } - - + public static void main(String[] args) { + } + + private static int binSearch(int[] r, int n, int k) { + int low = 1; + int high = n; + while (low <= high) { + int mid = (low + high) / 2; + if (r[mid] > k) { + high = mid - 1; + } else if (r[mid] < k) { + low = mid + 1; + } else { + return mid; + } + } + return 0; + } + } diff --git a/src/com/duweri/interview/datastructure/ReBuildBinaryTree.java b/src/com/duweri/interview/datastructure/ReBuildBinaryTree.java index 2b3e9dd..a4ba960 100644 --- a/src/com/duweri/interview/datastructure/ReBuildBinaryTree.java +++ b/src/com/duweri/interview/datastructure/ReBuildBinaryTree.java @@ -2,8 +2,8 @@ /** - * 已知前序遍历和后续遍历重建二叉树 - * @author 杜伟 + * 宸茬煡鍓嶅簭閬嶅巻鍜屽悗缁亶鍘嗛噸寤轰簩鍙夋爲 + * @author 鏉滀紵 */ public class ReBuildBinaryTree { @@ -18,23 +18,23 @@ public TreeNode reConstructBinaryTree(int [] pre,int [] in) { TreeNode root=reConstructBinaryTree(pre,0,pre.length-1,in,0,in.length-1); return root; } - //前序遍历{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6} + //鍓嶅簭閬嶅巻{1,2,4,7,3,5,6,8}鍜屼腑搴忛亶鍘嗗簭鍒梴4,7,2,1,5,3,8,6} private TreeNode reConstructBinaryTree(int [] pre,int startPre,int endPre,int [] in,int startIn,int endIn) { if(startPre>endPre||startIn>endIn) return null; - TreeNode root=new TreeNode(pre[startPre]);//前序遍历的第一个结点 + TreeNode root=new TreeNode(pre[startPre]);//鍓嶅簭閬嶅巻鐨勭涓涓粨鐐 - for(int i=startIn;i<=endIn;i++){//遍历中序数组 - if(in[i]==pre[startPre]){ //如果中序的某节点和前序一样 - //递归左边 + for(int i=startIn;i<=endIn;i++){//閬嶅巻涓簭鏁扮粍 + if(in[i]==pre[startPre]){ //濡傛灉涓簭鐨勬煇鑺傜偣鍜屽墠搴忎竴鏍 + //閫掑綊宸﹁竟 root.left=reConstructBinaryTree(pre,startPre+1,startPre+i-startIn,in,startIn,i-1); - //递归右边 + //閫掑綊鍙宠竟 root.right=reConstructBinaryTree(pre,i-startIn+startPre+1,endPre,in,i+1,endIn); } - }//循环完数组结束 + }//寰幆瀹屾暟缁勭粨鏉 - return root;//返回根节点 + return root;//杩斿洖鏍硅妭鐐 } diff --git a/src/com/duweri/interview/datastructure/Sort.java b/src/com/duweri/interview/datastructure/Sort.java index fb36ba7..3853917 100644 --- a/src/com/duweri/interview/datastructure/Sort.java +++ b/src/com/duweri/interview/datastructure/Sort.java @@ -1,148 +1,149 @@ package com.duweri.interview.datastructure; -import javax.management.Descriptor; - public class Sort { - public static void main(String[] args) { - int[] testArr = {12,27,19,39,16,49,61,40,20,94,63,13,27,31,38,43,11,44,81,29,33,88,60,80,51,4,0,1,22,9,8}; - Sort.insertSort(testArr); + public static void main(String[] args) { + int[] testArr = {12, 27, 19, 39, 16, 49, 61, 40, 20, 94, 63, 13, 27, 31, 38, 43, 11, 44, 81, 29, 33, 88, 60, 80, 51, 4, 0, 1, 22, 9, 8}; + Sort.insertSort(testArr); // Sort.bubbleSort(testArr); // Sort.quickSort(testArr, 0, testArr.length-1); // Sort.selectSort(testArr); - Sort.display(testArr); - } - - public static void display(int[] arr){ - for (int i = 0; i < arr.length; i++) { - System.out.print(arr[i]+","); - } - } - - /** - * 插入排序 - * 关键:1、临时变量保存待排序的数字 - * 2、边比较边后移 - * 适用情况:序列基本有序的时候 - */ - public static void insertSort(int[] arr){ - for (int i = 1; i < arr.length; i++) { - int temp = arr[i];//临时保存待插入序列 - int j;//下面先保证J大于0再去访问arr[j]!!!! - for (j = i-1;j >= 0 && temp > arr[j]; j--) {//带插入序列大于当前序列就前移--》从大到小排列 - arr[j+1] = arr[j]; - } - arr[j+1]=temp; - } - } - /** - * 希尔排序 - */ - public static void shellSort(int[] arr){ - - for (int i = arr.length/2; i >= 1; i=i/2) {//子序列的划分 - - } - - } - /** - * 冒泡排序 - * 关键:1、外循环标识无序区和有序区 - * 2、内循环每次将一个无序区的(最大)数字排到最前面 - */ - public static void bubbleSort(int[] arr){ - for (int i = 0; i i; j--) {//从最后一个开始遍历 - if (arr[j]>arr[j-1]) { - int temp = arr[j];//swap - arr[j] = arr[j-1]; - arr[j-1] = temp; - } - } - } - } - - /** - * 快速排序 - * 关键: 1、选轴值 - * 2、一次划分 - * 3、递归快排 - */ - public static void quickSort(int[] arr,int start,int end){ - if(start=pivotKey){ - right--; - } - while(left= 0 && temp > arr[j]; j--) {//甯︽彃鍏ュ簭鍒楀ぇ浜庡綋鍓嶅簭鍒楀氨鍓嶇Щ--銆嬩粠澶у埌灏忔帓鍒 + arr[j + 1] = arr[j]; + } + arr[j + 1] = temp; + } + } + + /** + * 甯屽皵鎺掑簭 + */ + public static void shellSort(int[] arr) { + + for (int i = arr.length / 2; i >= 1; i = i / 2) {//瀛愬簭鍒楃殑鍒掑垎 + + } + + } + + /** + * 鍐掓场鎺掑簭 + * 鍏抽敭锛1銆佸寰幆鏍囪瘑鏃犲簭鍖哄拰鏈夊簭鍖 + * 2銆佸唴寰幆姣忔灏嗕竴涓棤搴忓尯鐨勶紙鏈澶э級鏁板瓧鎺掑埌鏈鍓嶉潰 + */ + public static void bubbleSort(int[] arr) { + for (int i = 0; i < arr.length - 1; i++) {//浠庡悗寰鍓嶆帹灏忕殑 + for (int j = arr.length - 1; j > i; j--) {//浠庢渶鍚庝竴涓紑濮嬮亶鍘 + if (arr[j] > arr[j - 1]) { + int temp = arr[j];//swap + arr[j] = arr[j - 1]; + arr[j - 1] = temp; + } + } + } + } + + /** + * 蹇熸帓搴 + * 鍏抽敭: 1銆侀夎酱鍊 + * 2銆佷竴娆″垝鍒 + * 3銆侀掑綊蹇帓 + */ + public static void quickSort(int[] arr, int start, int end) { + if (start < end) { + int middle = partition(arr, start, end); + quickSort(arr, start, middle - 1); + quickSort(arr, middle + 1, end); + } + } + + /** + * 浠rr[0]涓哄熀鍑嗚繘琛屼竴娆″垝鍒嗙畻娉曪紝宸﹁竟閮藉皬浜巃rr[0]锛屽彸杈归兘澶т簬arr[0] + */ + private static int partition(int[] arr, int first, int end) { + while (first < end) { + //鍏堟壂鎻忓彸绔 + while (first < end && arr[first] < arr[end]) { + end--; + } + if (first < end) { + int temp = arr[end];//swap + arr[end] = arr[first]; + arr[first] = temp; + first++; + } + //鎵弿宸﹁竟 + while (first < end && arr[first] < arr[end]) { + first++; + } + if (first < end) { + int temp = arr[end];//swap + arr[end] = arr[first]; + arr[first] = temp; + end--; + } + } + return first; + } + + private static int partition2(int[] arr, int left, int right) { + int pivotKey = arr[left]; + int pivotePointer = left; + + while (left < right) { + while (left < right && arr[right] >= pivotKey) { + right--; + } + while (left < right && arr[left] <= pivotKey) { + left++; + } // swap(arr,left,right); - } + } // swap(arr,pivotePointer,left); - return left; - } - - - /** - * 选择排序: O(n^2) - * 每次遍历无序区选出最小的 - */ - public static void selectSort(int[] arr){ - int minIndex = 0; - for (int i = 0; i < arr.length-1; i++) { - minIndex = i;//指向最小的值的角标 - for (int j = i+1; j < arr.length; j++) {//遍历无序区 - if(arr[j] < arr[minIndex]){ - minIndex = j; - } - } - if (minIndex != i) { //无序区遍历完了,找到最小的角标了,交换 - int temp = arr[minIndex]; - arr[minIndex] = arr[i]; - arr[i] = temp; - } - } - } - + return left; + } + + + /** + * 閫夋嫨鎺掑簭锛 O锛坣^2锛 + * 姣忔閬嶅巻鏃犲簭鍖洪夊嚭鏈灏忕殑 + */ + public static void selectSort(int[] arr) { + int minIndex = 0; + for (int i = 0; i < arr.length - 1; i++) { + minIndex = i;//鎸囧悜鏈灏忕殑鍊肩殑瑙掓爣 + for (int j = i + 1; j < arr.length; j++) {//閬嶅巻鏃犲簭鍖 + if (arr[j] < arr[minIndex]) { + minIndex = j; + } + } + if (minIndex != i) { //鏃犲簭鍖洪亶鍘嗗畬浜嗭紝鎵惧埌鏈灏忕殑瑙掓爣浜嗭紝浜ゆ崲 + int temp = arr[minIndex]; + arr[minIndex] = arr[i]; + arr[i] = temp; + } + } + } + } diff --git a/src/com/duweri/interview/datastructure/TraversalBinaryTree.java b/src/com/duweri/interview/datastructure/TraversalBinaryTree.java index 3b26e1c..cb096d9 100644 --- a/src/com/duweri/interview/datastructure/TraversalBinaryTree.java +++ b/src/com/duweri/interview/datastructure/TraversalBinaryTree.java @@ -1,210 +1,248 @@ package com.duweri.interview.datastructure; -import java.util.ArrayDeque; -import java.util.Deque; -import java.util.Stack; +import java.util.*; +/** + * 浜屽弶鏍戠殑閬嶅巻 + */ public class TraversalBinaryTree { - private void printNode(Node node) { - System.out.print(node.getData()); - } - - /** - * 先序遍历---递归 - */ - public void theFirstTraversal(Node root) { - printNode(root); // 根 - if (root.getLeftNode() != null) { // 左 - theFirstTraversal(root.getLeftNode()); - } - if (root.getRightNode() != null) { // 右 - theFirstTraversal(root.getRightNode()); - } - } - - /** - * 中序遍历---递归 - */ - public void theInOrderTraversal(Node root) { - if (root.getLeftNode() != null) { // 左 - theInOrderTraversal(root.getLeftNode()); - } - printNode(root); // 中 - if (root.getRightNode() != null) { - theInOrderTraversal(root.getRightNode());// 右 - } - } - - /** - * 后序遍历---递归 - */ - public void thePostOrderTraversal(Node root) { - if (root.getLeftNode() != null) { - thePostOrderTraversal(root.getLeftNode()); - } - if (root.getRightNode() != null) { - thePostOrderTraversal(root.getRightNode()); - } - printNode(root); - } - /** - * 前序遍历---非递归算法 - */ - public void theFirstTraversal_Stack(Node root) { - Stack stack = new Stack();//初始化栈 - Node node = root; //遍历过程中移动此节点 - while (node != null || stack.size() > 0) { // 将所有左孩子压栈 - if (node != null) { //节点不为空, - printNode(node);// 输出该节点 - stack.push(node);//节点入栈 - node = node.getLeftNode();//指向左孩子 - } else { //节点为空 - node = stack.pop();//出栈返回,去遍历右孩子 - node = node.getRightNode(); - } - } - } - /** - * 中序遍历---非递归算法 - */ - public void theInOrderTraversal_Stack(Node root) { - Stack stack = new Stack();//初始化栈 - Node node = root; //临时指针节点 - while (node != null || stack.size() > 0) {//栈不空或者节点不空 - if (node != null) { //节点不空的情况 - stack.push(node); - node = node.getLeftNode(); - } else { //栈不空的情况 - node = stack.pop(); - printNode(node); - node = node.getRightNode(); - } - } - } - /** - * 后序遍历---非递归算法 - */ - public void thePostOrderTraversal_Stack(Node root) { - Stack stack = new Stack(); - Stack output = new Stack();// 构造一个中间栈来存储逆后序遍历的结果 - Node node = root; - while (node != null || stack.size() > 0) { - if (node != null) { - output.push(node); - stack.push(node); - node = node.getRightNode(); - } else { - node = stack.pop(); - node = node.getLeftNode(); - - } - } - while (output.size() > 0) { - printNode(output.pop()); - } - } - - /** - * 深度优先遍历二叉树 - * @param root 根节点 - */ - public void depthFirstSearch(Node root){ - Stack stack = new Stack(); - stack.push(root); - Node node = root; - while(!stack.empty()){ - node = stack.pop(); - printNode(node); //遍历根结点 - if(node.getRightNode() != null){ - stack.push(node.getRightNode()); //先将右子树压栈 - } - if(node.getLeftNode() != null){ - stack.push(node.getLeftNode()); //再将左子树压栈 - } - } - } - /** - * 广度优先遍历二叉树 - * @param node 根节点 - */ - public void breadthFirst(Node node) { - Deque nodeDeque = new ArrayDeque(); - nodeDeque.add(node); - while (!nodeDeque.isEmpty()) { - node = nodeDeque.peekFirst(); - printNode(node); - if (node.getLeftNode()!=null) { - nodeDeque.add(node.getLeftNode()); - } - if (node.getRightNode()!=null) { - nodeDeque.add(node.getRightNode()); - } - } - } - - - public static void main(String[] args) { - TraversalBinaryTree tree = new TraversalBinaryTree(); - Node root = tree.init(); - System.out.println("先序遍历"); - tree.theFirstTraversal(root); - System.out.println(""); - System.out.println("中序遍历"); - tree.theInOrderTraversal(root); - System.out.println(""); - System.out.println("后序遍历"); - tree.thePostOrderTraversal(root); - System.out.println(""); - } - - public Node init() {// 注意必须逆序建立,先建立子节点,再逆序往上建立,因为非叶子结点会使用到下面的节点,而初始化是按顺序初始化的,不逆序建立会报错 - Node J = new Node(8, null, null); - Node H = new Node(4, null, null); - Node G = new Node(2, null, null); - Node F = new Node(7, null, J); - Node E = new Node(5, H, null); - Node D = new Node(1, null, G); - Node C = new Node(9, F, null); - Node B = new Node(3, D, E); - Node A = new Node(6, B, C); - return A; // 返回根节点 - } - - public class Node { - private int data; - private Node leftNode; - private Node rightNode; - - public Node(int data, Node leftNode, Node rightNode) { - this.data = data; - this.leftNode = leftNode; - this.rightNode = rightNode; - } - - public int getData() { - return data; - } - - public void setData(int data) { - this.data = data; - } - - public Node getLeftNode() { - return leftNode; - } - - public void setLeftNode(Node leftNode) { - this.leftNode = leftNode; - } - - public Node getRightNode() { - return rightNode; - } - - public void setRightNode(Node rightNode) { - this.rightNode = rightNode; - } - } + private void printNode(Node node) { + System.out.print(node.getData()); + } + + /** + * 鍏堝簭閬嶅巻---閫掑綊 + */ + public void theFirstTraversal(Node root) { + printNode(root); // 鏍 + if (root.getLeftNode() != null) { // 宸 + theFirstTraversal(root.getLeftNode()); + } + if (root.getRightNode() != null) { // 鍙 + theFirstTraversal(root.getRightNode()); + } + } + + /** + * 涓簭閬嶅巻---閫掑綊 + */ + public void theInOrderTraversal(Node root) { + if (root.getLeftNode() != null) { // 宸 + theInOrderTraversal(root.getLeftNode()); + } + printNode(root); // 涓 + if (root.getRightNode() != null) { + theInOrderTraversal(root.getRightNode());// 鍙 + } + } + + /** + * 鍚庡簭閬嶅巻---閫掑綊 + */ + public void thePostOrderTraversal(Node root) { + if (root.getLeftNode() != null) { + thePostOrderTraversal(root.getLeftNode()); + } + if (root.getRightNode() != null) { + thePostOrderTraversal(root.getRightNode()); + } + printNode(root); + } + + /** + * 鍓嶅簭閬嶅巻---闈為掑綊绠楁硶 + */ + public void theFirstTraversal_Stack(Node root) { + Stack stack = new Stack();//鍒濆鍖栨爤 + Node node = root; //閬嶅巻杩囩▼涓Щ鍔ㄦ鑺傜偣 + while (node != null || stack.size() > 0) { // 灏嗘墍鏈夊乏瀛╁瓙鍘嬫爤 + if (node != null) { //鑺傜偣涓嶄负绌猴紝 + printNode(node);// 杈撳嚭璇ヨ妭鐐 + stack.push(node);//鑺傜偣鍏ユ爤 + node = node.getLeftNode();//鎸囧悜宸﹀瀛 + } else { //鑺傜偣涓虹┖ + node = stack.pop();//鍑烘爤杩斿洖锛屽幓閬嶅巻鍙冲瀛 + node = node.getRightNode(); + } + } + } + + /** + * 涓簭閬嶅巻---闈為掑綊绠楁硶 + */ + public void theInOrderTraversal_Stack(Node root) { + Stack stack = new Stack();//鍒濆鍖栨爤 + Node node = root; //涓存椂鎸囬拡鑺傜偣 + while (node != null || stack.size() > 0) {//鏍堜笉绌烘垨鑰呰妭鐐逛笉绌 + if (node != null) { //鑺傜偣涓嶇┖鐨勬儏鍐 + stack.push(node); + node = node.getLeftNode(); + } else { //鏍堜笉绌虹殑鎯呭喌 + node = stack.pop(); + printNode(node); + node = node.getRightNode(); + } + } + } + + /** + * 鍚庡簭閬嶅巻---闈為掑綊绠楁硶 + */ + public void thePostOrderTraversal_Stack(Node root) { + Stack stack = new Stack(); + Stack output = new Stack();// 鏋勯犱竴涓腑闂存爤鏉ュ瓨鍌ㄩ嗗悗搴忛亶鍘嗙殑缁撴灉 + Node node = root; + while (node != null || stack.size() > 0) { + if (node != null) { + output.push(node); + stack.push(node); + node = node.getRightNode(); + } else { + node = stack.pop(); + node = node.getLeftNode(); + + } + } + while (output.size() > 0) { + printNode(output.pop()); + } + } + + /** + * 娣卞害浼樺厛閬嶅巻浜屽弶鏍 + * + * @param root 鏍硅妭鐐 + */ + public void depthFirstSearch(Node root) { + Stack stack = new Stack(); + stack.push(root); + Node node = root; + while (!stack.empty()) { + node = stack.pop(); + printNode(node); //閬嶅巻鏍圭粨鐐 + if (node.getRightNode() != null) { + stack.push(node.getRightNode()); //鍏堝皢鍙冲瓙鏍戝帇鏍 + } + if (node.getLeftNode() != null) { + stack.push(node.getLeftNode()); //鍐嶅皢宸﹀瓙鏍戝帇鏍 + } + } + } + + /** + * 骞垮害浼樺厛閬嶅巻浜屽弶鏍 + * + * @param node 鏍硅妭鐐 + */ + public void breadthFirst(Node node) { + Deque nodeDeque = new ArrayDeque(); + nodeDeque.add(node); + while (!nodeDeque.isEmpty()) { + node = nodeDeque.removeFirst();//鍙栧嚭骞剁Щ闄!! + printNode(node); + if (node.getLeftNode() != null) { + nodeDeque.add(node.getLeftNode()); + } + if (node.getRightNode() != null) { + nodeDeque.add(node.getRightNode()); + } + } + } + + public void breadthFirst2(Node node){ + Queue queue = new LinkedList<>(); + queue.offer(node); + while (!queue.isEmpty()){ + node = queue.poll(); + printNode(node); + if (node.getLeftNode() != null){ + queue.offer(node.getLeftNode()); + } + if (node.getRightNode() != null){ + queue.offer(node.getRightNode()); + } + } + } + + + public static void main(String[] args) { + TraversalBinaryTree tree = new TraversalBinaryTree(); + Node root = tree.init(); + System.out.println("鍏堝簭閬嶅巻"); + tree.theFirstTraversal(root); + System.out.println(""); + System.out.println("涓簭閬嶅巻"); + tree.theInOrderTraversal(root); + System.out.println(""); + System.out.println("鍚庡簭閬嶅巻"); + tree.thePostOrderTraversal(root); + System.out.println(""); + System.out.println("骞垮害浼樺厛"); + tree.breadthFirst(root); + System.out.println(""); + System.out.println("骞垮害浼樺厛2"); + tree.breadthFirst2(root); + } + + public Node init() {// 娉ㄦ剰蹇呴』閫嗗簭寤虹珛锛屽厛寤虹珛瀛愯妭鐐癸紝鍐嶉嗗簭寰涓婂缓绔嬶紝鍥犱负闈炲彾瀛愮粨鐐逛細浣跨敤鍒颁笅闈㈢殑鑺傜偣锛 + // 鑰屽垵濮嬪寲鏄寜椤哄簭鍒濆鍖栫殑锛屼笉閫嗗簭寤虹珛浼氭姤閿 + Node J = new Node("I",8, null, null); + Node H = new Node("H",4, null, null); + Node G = new Node("G",2, null, null); + Node F = new Node("F",7, null, J); + Node E = new Node("E",5, H, null); + Node D = new Node("D",1, null, G); + Node C = new Node("C",9, F, null); + Node B = new Node("B",3, D, E); + Node A = new Node("A",6, B, C); + return A; // 杩斿洖鏍硅妭鐐 + } + + /** + * A(6) + * B(3) C(9) + * D(1) E(5) F(7) null + * null G(2) H(4) null null J(8) + * null null + */ + + public class Node { + private int data; + private String name; + private Node leftNode; + private Node rightNode; + + public Node(String name, int data, Node leftNode, Node rightNode) { + this.name = name; + this.data = data; + this.leftNode = leftNode; + this.rightNode = rightNode; + } + + public int getData() { + return data; + } + + public void setData(int data) { + this.data = data; + } + + public Node getLeftNode() { + return leftNode; + } + + public void setLeftNode(Node leftNode) { + this.leftNode = leftNode; + } + + public Node getRightNode() { + return rightNode; + } + + public void setRightNode(Node rightNode) { + this.rightNode = rightNode; + } + } } diff --git a/src/com/duweri/interview/search/BinarySearch.java b/src/com/duweri/interview/search/BinarySearch.java new file mode 100644 index 0000000..1e38b85 --- /dev/null +++ b/src/com/duweri/interview/search/BinarySearch.java @@ -0,0 +1,29 @@ +package com.duweri.interview.search; + +public class BinarySearch { + + /** + * 浜屽垎鏌ユ壘鍙堢О鎶樺崐鏌ユ壘锛屽畠鏄竴绉嶆晥鐜囪緝楂樼殑鏌ユ壘鏂规硶銆 銆愪簩鍒嗘煡鎵捐姹傘戯細 + * 1.蹇呴』閲囩敤椤哄簭瀛樺偍缁撴瀯 2.蹇呴』鎸夊叧閿瓧澶у皬鏈夊簭鎺掑垪銆 + * + * @param array 鏈夊簭鏁扮粍 + * @param searchKey 鏌ユ壘鍏冪礌 + * @return searchKey鐨勬暟缁勪笅鏍囷紝娌℃壘鍒拌繑鍥-1 + */ + public static int binarySearch(int[] array, int searchKey) { + + int low = 0; + int high = array.length - 1; + while (low <= high) { + int middle = (low + high) / 2; + if (searchKey == array[middle]) { + return middle; + } else if (searchKey < array[middle]) { + high = middle - 1; + } else { + low = middle + 1; + } + } + return -1; + } +} diff --git a/src/com/duweri/interview/search/OrderSearch.java b/src/com/duweri/interview/search/OrderSearch.java new file mode 100644 index 0000000..699c144 --- /dev/null +++ b/src/com/duweri/interview/search/OrderSearch.java @@ -0,0 +1,21 @@ +package com.duweri.interview.search; + +public class OrderSearch { + + /**椤哄簭鏌ユ壘骞冲潎鏃堕棿澶嶆潅搴 O锛坣锛 + * @param searchKey 瑕佹煡鎵剧殑鍊 + * @param array 鏁扮粍锛堜粠杩欎釜鏁扮粍涓煡鎵撅級 + * @return 鏌ユ壘缁撴灉锛堟暟缁勭殑涓嬫爣浣嶇疆锛 + */ + public static int orderSearch(int searchKey,int[] array){ + if(array==null||array.length<1) + return -1; + for(int i=0;i numbers[j + 1]){ //浜ゆ崲涓ゆ暟浣嶇疆 + temp = numbers[j]; + numbers[j] = numbers[j + 1]; + numbers[j + 1] = temp; + } + } + } + } + +} diff --git a/src/com/duweri/interview/sort/HeapSort.java b/src/com/duweri/interview/sort/HeapSort.java new file mode 100644 index 0000000..dca5d48 --- /dev/null +++ b/src/com/duweri/interview/sort/HeapSort.java @@ -0,0 +1,75 @@ +package com.duweri.interview.sort; + +import java.util.Arrays; + +public class HeapSort { + public static void main(String[] args) { + int[] array = new int[] { 2, 1, 4, 3, 6, 5, 8, 7 }; + sort(array); + System.out.println(Arrays.toString(array)); + } + + public static void sort(int[] array) { + // 鎸夌収瀹屽叏浜屽弶鏍戠殑鐗圭偣锛屼粠鏈鍚庝竴涓潪鍙跺瓙鑺傜偣寮濮嬶紝瀵逛簬鏁存5鏍戣繘琛屽ぇ鏍瑰爢鐨勮皟鏁 + // 涔熷氨鏄锛屾槸鎸夌収鑷笅鑰屼笂锛屾瘡涓灞傞兘鏄嚜鍙冲悜宸︽潵杩涜璋冩暣鐨 + // 娉ㄦ剰锛岃繖閲屽厓绱犵殑绱㈠紩鏄粠0寮濮嬬殑 + // 鍙︿竴浠堕渶瑕佹敞鎰忕殑浜嬫儏锛岃繖閲岀殑寤哄爢锛屾槸鐢ㄥ爢璋冩暣鐨勬柟寮忔潵鍋氱殑 + // 鍫嗚皟鏁寸殑閫昏緫鍦ㄥ缓鍫嗗拰鍚庣画鎺掑簭杩囩▼涓鐢ㄧ殑 + for (int i = array.length / 2 - 1; i >= 0; i--) { + adjustHeap(array, i, array.length); + } + + // 涓婅堪閫昏緫锛屽缓鍫嗙粨鏉 + // 涓嬮潰锛屽紑濮嬫帓搴忛昏緫 + for (int j = array.length - 1; j > 0; j--) { + // 鍏冪礌浜ゆ崲 + // 璇存槸浜ゆ崲锛屽叾瀹炶川灏辨槸鎶婂ぇ椤跺爢鐨勬牴鍏冪礌锛屾斁鍒版暟缁勭殑鏈鍚庯紱鎹㈠彞璇濊锛屽氨鏄瘡涓娆$殑鍫嗚皟鏁翠箣鍚庯紝閮戒細鏈変竴涓厓绱犲埌杈捐嚜宸辩殑鏈缁堜綅缃 + swap(array, 0, j); + // 鍏冪礌浜ゆ崲涔嬪悗锛屾鏃犵枒闂紝鏈鍚庝竴涓厓绱犳棤闇鍐嶈冭檻鎺掑簭闂浜嗐 + // 鎺ヤ笅鏉ユ垜浠渶瑕佹帓搴忕殑锛屽氨鏄凡缁忓幓鎺変簡閮ㄥ垎鍏冪礌鐨勫爢浜嗭紝杩欎篃鏄负浠涔堟鏂规硶鏀惧湪寰幆閲岀殑鍘熷洜 + // 鑰岃繖閲岋紝瀹炶川涓婃槸鑷笂鑰屼笅锛岃嚜宸﹀悜鍙宠繘琛岃皟鏁寸殑 + adjustHeap(array, 0, j); + } + } + + /** + * 杩欓噷锛屾槸鏁翠釜鍫嗘帓搴忔渶鍏抽敭鐨勫湴鏂癸紝姝f槸鍥犱负鎶婅繖涓柟娉曟娊鍙栧嚭鏉ワ紝鎵嶆洿濂界悊瑙d簡鍫嗘帓搴忕殑绮鹃珦锛屼細灏藉彲鑳戒粩缁嗚瑙 + */ + public static void adjustHeap(int[] array, int i, int length) { + // 鍏堟妸褰撳墠鍏冪礌鍙栧嚭鏉ワ紝鍥犱负褰撳墠鍏冪礌鍙兘瑕佷竴鐩寸Щ鍔 + int temp = array[i]; + // 鍙互鍙傜収sort涓殑璋冪敤閫昏緫锛屽湪鍫嗗缓鎴愶紝涓斿畬鎴愮涓娆′氦鎹箣鍚庯紝瀹炶川涓奿=0锛涗篃灏辨槸璇达紝鏄粠鏍规墍鍦ㄧ殑鏈灏忓瓙鏍戝紑濮嬭皟鏁寸殑 + // 鎺ヤ笅鏉ョ殑璁茶В锛岄兘鏄寜鐓鐨勫垵濮嬪间负0鏉ヨ杩扮殑 + // 杩欎竴娈靛緢濂界悊瑙o紝濡傛灉i=0锛涘垯k=1锛沰+1=2 + // 瀹炶川涓婏紝灏辨槸鏍硅妭鐐瑰拰鍏跺乏鍙冲瓙鑺傜偣璁版ф瘮杈冿紝璁﹌鎸囧悜杩欎釜涓嶈秴杩囦笁涓妭鐐圭殑瀛愭爲涓渶澶х殑鍊 + // 杩欓噷锛屽繀椤昏璇翠笅涓轰粈涔坘鍊兼槸璺宠穬鎬х殑銆 + // 棣栧厛锛屼妇涓緥瀛愶紝濡傛灉a[0] > a[1]&&a[0]>a[2],璇存槑0,1,2杩欐5鏍戜笉闇瑕佽皟鏁达紝閭d箞锛屼笅涓姝ヨ鍒板摢涓妭鐐逛簡鍛紵鑲畾鏄痑[1]鎵鍦ㄧ殑瀛愭爲浜嗭紝 + // 涔熷氨鏄锛屾槸浠ユ湰鑺傜偣鐨勫乏瀛愯妭鐐逛负鏍圭殑閭f5灏忕殑瀛愭爲 + // 鑰屽鏋渁[0} temp) { + swap(array, i, k); + // 涓嬮潰灏辨槸闈炲父鍏抽敭鐨勪竴姝ヤ簡 + // 濡傛灉瀛愯妭鐐规洿鎹簡锛岄偅涔堬紝浠ュ瓙鑺傜偣涓烘牴鐨勫瓙鏍戜細涓嶄細鍙楀埌褰卞搷鍛紵 + // 鎵浠ワ紝寰幆瀵瑰瓙鑺傜偣鎵鍦ㄧ殑鏍戠户缁繘琛屽垽鏂 + i = k; + // 濡傛灉涓嶇敤浜ゆ崲锛岄偅涔堬紝灏辩洿鎺ョ粓姝㈠惊鐜簡 + } else { + break; + } + } + } + + public static void swap(int[] arr, int a, int b) { + int temp = arr[a]; + arr[a] = arr[b]; + arr[b] = temp; + } +} diff --git a/src/com/duweri/interview/sort/InsertSort.java b/src/com/duweri/interview/sort/InsertSort.java new file mode 100644 index 0000000..e0223b5 --- /dev/null +++ b/src/com/duweri/interview/sort/InsertSort.java @@ -0,0 +1,31 @@ +package com.duweri.interview.sort; + +public class InsertSort { + + /** + * 鎻掑叆鎺掑簭 + *

+ * 浠庣涓涓厓绱犲紑濮嬶紝璇ュ厓绱犲彲浠ヨ涓哄凡缁忚鎺掑簭 + * 鍙栧嚭涓嬩竴涓厓绱狅紝鍦ㄥ凡缁忔帓搴忕殑鍏冪礌搴忓垪涓粠鍚庡悜鍓嶆壂鎻 + * 濡傛灉璇ュ厓绱狅紙宸叉帓搴忥級澶т簬鏂板厓绱狅紝灏嗚鍏冪礌绉诲埌涓嬩竴浣嶇疆 + * 閲嶅姝ラ3锛岀洿鍒版壘鍒板凡鎺掑簭鐨勫厓绱犲皬浜庢垨鑰呯瓑浜庢柊鍏冪礌鐨勪綅缃 + * 灏嗘柊鍏冪礌鎻掑叆鍒拌浣嶇疆涓 + * 閲嶅姝ラ2 + * + * @param numbers 寰呮帓搴忔暟缁 + */ + public static void insertSort(int[] numbers) { + int size = numbers.length; + int temp = 0; + int j = 0; + + for (int i = 0; i < size; i++) { + temp = numbers[i]; + //鍋囧temp姣斿墠闈㈢殑鍊煎皬锛屽垯灏嗗墠闈㈢殑鍊煎悗绉 + for (j = i; j > 0 && temp < numbers[j - 1]; j--) { + numbers[j] = numbers[j - 1]; + } + numbers[j] = temp; + } + } +} diff --git a/src/com/duweri/interview/sort/MergeSort.java b/src/com/duweri/interview/sort/MergeSort.java new file mode 100644 index 0000000..34ffe75 --- /dev/null +++ b/src/com/duweri/interview/sort/MergeSort.java @@ -0,0 +1,53 @@ +package com.duweri.interview.sort; + +/** + * 褰掑苟鎺掑簭 + * http://www.cnblogs.com/chengxiao/p/6194356.html + */ +public class MergeSort { + + public static void sort(int[] arr) { + int[] temp = new int[arr.length];//鍦ㄦ帓搴忓墠锛屽厛寤哄ソ涓涓暱搴︾瓑浜庡師鏁扮粍闀垮害鐨勪复鏃舵暟缁勶紝閬垮厤閫掑綊涓绻佸紑杈熺┖闂 + sort(arr, 0, arr.length - 1, temp); + } + + /** + * + * @param arr 寰呮帓搴忔暟缁 + * @param left + * @param right + * @param temp 涓存椂鏁扮粍 + */ + private static void sort(int[] arr, int left, int right, int[] temp) { + if (left < right) { + int mid = (left + right) / 2; + sort(arr, left, mid, temp);//宸﹁竟褰掑苟鎺掑簭锛屼娇寰楀乏瀛愬簭鍒楁湁搴 + sort(arr, mid + 1, right, temp);//鍙宠竟褰掑苟鎺掑簭锛屼娇寰楀彸瀛愬簭鍒楁湁搴 + merge(arr, left, mid, right, temp);//灏嗕袱涓湁搴忓瓙鏁扮粍鍚堝苟鎿嶄綔 + } + } + + private static void merge(int[] arr, int left, int mid, int right, int[] temp) { + int i = left;//宸﹀簭鍒楁寚閽 + int j = mid + 1;//鍙冲簭鍒楁寚閽 + int t = 0;//涓存椂鏁扮粍鎸囬拡 + while (i <= mid && j <= right) { + if (arr[i] <= arr[j]) { + temp[t++] = arr[i++]; + } else { + temp[t++] = arr[j++]; + } + } + while (i <= mid) {//灏嗗乏杈瑰墿浣欏厓绱犲~鍏呰繘temp涓 + temp[t++] = arr[i++]; + } + while (j <= right) {//灏嗗彸搴忓垪鍓╀綑鍏冪礌濉厖杩泃emp涓 + temp[t++] = arr[j++]; + } + t = 0; + //灏唗emp涓殑鍏冪礌鍏ㄩ儴鎷疯礉鍒板師鏁扮粍涓 + while (left <= right) { + arr[left++] = temp[t++]; + } + } +} diff --git a/src/com/duweri/interview/sort/QuickSort.java b/src/com/duweri/interview/sort/QuickSort.java new file mode 100644 index 0000000..488988b --- /dev/null +++ b/src/com/duweri/interview/sort/QuickSort.java @@ -0,0 +1,61 @@ +package com.duweri.interview.sort; + +import java.util.Arrays; + +/** + * https://juejin.im/post/5b55660ee51d4519202e2003 + */ +public class QuickSort { + private static void printArr(int[] arr) { + for (int anArr : arr) { + System.out.print(anArr + " "); + } + } + + /** + * 蹇帓涓娆″垝鍒 + * @param arr + * @param left + * @param right + * @return + */ + private static int partition(int[] arr, int left, int right) { + int temp = arr[left]; + while (right > left) { + // 鍏堝垽鏂熀鍑嗘暟鍜屽悗闈㈢殑鏁颁緷娆℃瘮杈 + while (temp <= arr[right] && left < right) { + --right; + } + // 褰撳熀鍑嗘暟澶т簬浜 arr[right]锛屽垯濉潙 + if (left < right) { + arr[left] = arr[right]; + ++left; + } + // 鐜板湪鏄 arr[right] 闇瑕佸~鍧戜簡 + while (temp >= arr[left] && left < right) { + ++left; + } + if (left < right) { + arr[right] = arr[left]; + --right; + } + } + arr[left] = temp; + return left; + } + + private static void quickSort(int[] arr, int left, int right) { + if (arr == null || left >= right || arr.length <= 1) + return; + int mid = partition(arr, left, right); + quickSort(arr, left, mid); + quickSort(arr, mid + 1, right); + } + + + public static void main(String[] args) { + int[] arr = {6, 4, 3, 2, 7, 9, 1, 8, 5}; + quickSort(arr, 0, arr.length - 1); + printArr(arr); + } +} diff --git a/src/com/duweri/interview/sort/SelectSort.java b/src/com/duweri/interview/sort/SelectSort.java new file mode 100644 index 0000000..1339c6a --- /dev/null +++ b/src/com/duweri/interview/sort/SelectSort.java @@ -0,0 +1,33 @@ +package com.duweri.interview.sort; + +public class SelectSort { + + /** + * 閫夋嫨鎺掑簭绠楁硶 + * 鍦ㄦ湭鎺掑簭搴忓垪涓壘鍒版渶灏忓厓绱狅紝瀛樻斁鍒版帓搴忓簭鍒楃殑璧峰浣嶇疆 + * 鍐嶄粠鍓╀綑鏈帓搴忓厓绱犱腑缁х画瀵绘壘鏈灏忓厓绱狅紝鐒跺悗鏀惧埌鎺掑簭搴忓垪鏈熬銆 + * 浠ユ绫绘帹锛岀洿鍒版墍鏈夊厓绱犲潎鎺掑簭瀹屾瘯銆 + * + * @param numbers + */ + public static void selectSort(int[] numbers) { + int size = numbers.length; //鏁扮粍闀垮害 + int temp = 0; //涓棿鍙橀噺 + + for (int i = 0; i < size; i++) { + int k = i; //寰呯‘瀹氱殑浣嶇疆,鏍囪鏈灏忓肩殑鍧愭爣 + //閫夋嫨鍑哄簲璇ュ湪绗琲涓綅缃殑鏁 + for (int j = size - 1; j > i; j--) { + if (numbers[j] < numbers[k]) { + k = j; + } + } + //浜ゆ崲涓や釜鏁 + temp = numbers[i]; + numbers[i] = numbers[k]; + numbers[k] = temp; + } + } + + +} diff --git a/src/com/duweri/interview/sort/ShellSort.java b/src/com/duweri/interview/sort/ShellSort.java new file mode 100644 index 0000000..a0cab9d --- /dev/null +++ b/src/com/duweri/interview/sort/ShellSort.java @@ -0,0 +1,37 @@ +package com.duweri.interview.sort; + +public class ShellSort { + + /** + * 甯屽皵鎺掑簭鐨勫師鐞:鏍规嵁闇姹傦紝濡傛灉浣犳兂瑕佺粨鏋滀粠澶у埌灏忔帓鍒楋紝瀹冧細棣栧厛灏嗘暟缁勮繘琛屽垎缁勶紝鐒跺悗灏嗚緝澶у肩Щ鍒板墠闈紝杈冨皬鍊 + * 绉诲埌鍚庨潰锛屾渶鍚庡皢鏁翠釜鏁扮粍杩涜鎻掑叆鎺掑簭锛岃繖鏍锋瘮璧蜂竴寮濮嬪氨鐢ㄦ彃鍏ユ帓搴忓噺灏戜簡鏁版嵁浜ゆ崲鍜岀Щ鍔ㄧ殑娆℃暟锛屽彲浠ヨ甯屽皵鎺掑簭鏄姞寮 + * 鐗堢殑鎻掑叆鎺掑簭 + * 鎷挎暟缁5, 2, 8, 9, 1, 3锛4鏉ヨ锛屾暟缁勯暱搴︿负7锛屽綋increment涓3鏃讹紝鏁扮粍鍒嗕负涓や釜搴忓垪 + * 5锛2锛8鍜9锛1锛3锛4锛岀涓娆℃帓搴忥紝9鍜5姣旇緝锛1鍜2姣旇緝锛3鍜8姣旇緝锛4鍜屾瘮鍏朵笅鏍囧煎皬increment鐨勬暟缁勫肩浉姣旇緝 + * 姝や緥瀛愭槸鎸夌収浠庡ぇ鍒板皬鎺掑垪锛屾墍浠ュぇ鐨勪細鎺掑湪鍓嶉潰锛岀涓娆℃帓搴忓悗鏁扮粍涓9, 2, 8, 5, 1, 3锛4 + * 绗竴娆″悗increment鐨勫煎彉涓3/2=1,姝ゆ椂瀵规暟缁勮繘琛屾彃鍏ユ帓搴忥紝 + * 瀹炵幇鏁扮粍浠庡ぇ鍒板皬鎺 + */ + + public static void shellSort(int[] data) { + int j = 0; + int temp = 0; + //姣忔灏嗘闀跨缉鐭负鍘熸潵鐨勪竴鍗 + for (int increment = data.length / 2; increment > 0; increment /= 2) { + for (int i = increment; i < data.length; i++) { + temp = data[i]; + for (j = i; j >= increment; j -= increment) { + if (temp > data[j - increment])//濡傛兂浠庡皬鍒板ぇ鎺掑彧闇淇敼杩欓噷 + { + data[j] = data[j - increment]; + } else { + break; + } + + } + data[j] = temp; + } + + } + } +} diff --git a/src/com/duweri/interview/string/StringTest.java b/src/com/duweri/interview/string/StringTest.java index 41c2b2c..41dae5e 100644 --- a/src/com/duweri/interview/string/StringTest.java +++ b/src/com/duweri/interview/string/StringTest.java @@ -1,7 +1,7 @@ package com.duweri.interview.string; /** - * 字符串内存分配 - * @author 杜伟 + * 瀛楃涓插唴瀛樺垎閰 + * @author 鏉滀紵 */ public class StringTest { diff --git a/src/com/duweri/interview/Test.java b/src/com/duweri/interview/string/Test.java similarity index 63% rename from src/com/duweri/interview/Test.java rename to src/com/duweri/interview/string/Test.java index 8a10202..b4a99f8 100644 --- a/src/com/duweri/interview/Test.java +++ b/src/com/duweri/interview/string/Test.java @@ -1,4 +1,4 @@ -package com.duweri.interview; +package com.duweri.interview.string; public class Test { @@ -18,13 +18,13 @@ public class Test { private static final String MESSAGE="taobao"; public static void main(String [] args) { - String a ="tao"+"bao";//在池中创建tao和bao,并指向“taobao”对象 - String b="tao";//指向池中的tao - String c="bao";//指向池中的bao - String d = b+c;//堆中创建d + String a ="tao"+"bao";//鍦ㄦ睜涓垱寤簍ao鍜宐ao锛屽苟鎸囧悜鈥渢aobao鈥濆璞 + String b="tao";//鎸囧悜姹犱腑鐨則ao + String c="bao";//鎸囧悜姹犱腑鐨刡ao + String d = b+c;//鍫嗕腑鍒涘缓d System.out.println(a==MESSAGE); System.out.println("-------------"); - System.out.println((b+c)==MESSAGE);//对象 + System.out.println((b+c)==MESSAGE);//瀵硅薄 System.out.println(d.hashCode()+"+"+MESSAGE.hashCode()); System.out.println((b+c).length()+"+"+MESSAGE.length()); diff --git a/src/com/duweri/interview/string/Test1.java b/src/com/duweri/interview/string/Test1.java index a6cd597..e0fb0e0 100644 --- a/src/com/duweri/interview/string/Test1.java +++ b/src/com/duweri/interview/string/Test1.java @@ -4,8 +4,8 @@ public class Test1 { public static void main(String[] args) { - String s1="abc"+"def";//1 池 - String s2=new String(s1);//2 堆 + String s1="abc"+"def";//1 姹 + String s2=new String(s1);//2 鍫 if(s1.equals(s2))//3 System.out.println(".equals succeeded");//4 if(s1==s2)//5 X diff --git a/src/com/duweri/interview/string/Test2.java b/src/com/duweri/interview/string/Test2.java index c9c0655..16fc12f 100644 --- a/src/com/duweri/interview/string/Test2.java +++ b/src/com/duweri/interview/string/Test2.java @@ -6,8 +6,7 @@ public class Test2 { * @param args */ public static void main(String[] args) { - // TODO Auto-generated method stub - + Integer i01=59; int i02=59; Integer i03=Integer.valueOf(59); diff --git a/src/com/duweri/interview/string/Test4.java b/src/com/duweri/interview/string/Test4.java new file mode 100644 index 0000000..5ddedfa --- /dev/null +++ b/src/com/duweri/interview/string/Test4.java @@ -0,0 +1,27 @@ +package com.duweri.interview.string; + +public class Test4 { + + public static void main(String[] args) { + Test4.test1(); + Test4.test2(); + } + + private static void test1(){ + String s1 ="abc"; + String s2 ="a"; + String s3 = "bc"; + String s4 = s2 + s3; + System.out.println(s1 == s4); + } + + + private static void test2(){ + String s1 ="abc"; + final String s2 ="a"; + final String s3 = "bc"; + String s4 = s2 + s3; + System.out.println(s1 == s4); + } + +} diff --git a/src/com/duweri/interview/trycatch/TryCatchFinally.java b/src/com/duweri/interview/trycatch/TryCatchFinally.java new file mode 100644 index 0000000..907d8c9 --- /dev/null +++ b/src/com/duweri/interview/trycatch/TryCatchFinally.java @@ -0,0 +1,23 @@ +package com.duweri.interview.trycatch; + +/** + * 鑰冨療浠g爜鎵ц娴佺▼锛 + * return a+b鍙槸灏嗚繑鍥炲间繚瀛樺湪浜嗕复鏃舵爤涓傚厛鎵цfinally锛岀劧鍚庤姹傝繑鍥炲懡浠わ紝鎵嶈繑鍥炰复鏃舵爤 + */ +public class TryCatchFinally { + + public int add(int a, int b) { + try { + return a + b; + } catch (Exception e) { + System.out.println("catch"); + } finally { + System.out.println("finally"); + } + return 0; + } + + public static void main(String[] args) { + System.out.println("=" + new TryCatchFinally().add(1, 5)); + } +} diff --git a/src/com/duweri/interview/trycatch/TryCatchFinally2.java b/src/com/duweri/interview/trycatch/TryCatchFinally2.java new file mode 100644 index 0000000..28813ac --- /dev/null +++ b/src/com/duweri/interview/trycatch/TryCatchFinally2.java @@ -0,0 +1,20 @@ +package com.duweri.interview.trycatch; + +public class TryCatchFinally2 { + + public static void test8(){ + try { + System.out.println("try"); + throw new Exception(); + } catch (Exception e) { + System.out.println("catch"); + return; + }finally{ + System.out.println("finally"); + } + } + + public static void main(String[] args) { + TryCatchFinally2.test8(); + } +} diff --git a/src/com/github/pedrovgs/problem1/BitsCounter.java b/src/com/github/pedrovgs/problem1/BitsCounter.java index 1ae9466..2229d3a 100644 --- a/src/com/github/pedrovgs/problem1/BitsCounter.java +++ b/src/com/github/pedrovgs/problem1/BitsCounter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2014 Pedro Vicente G贸mez S谩nchez. + * Copyright (C) 2014 Pedro Vicente G璐竚ez S璋﹏chez. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package com.github.pedrovgs.problem1; /** - * 二进制计数器 + * 浜岃繘鍒惰鏁板櫒 * Given a positive integer passed as parameter return * the number of bits that parameter contains * equals to one in a binary representation. diff --git a/src/com/github/pedrovgs/problem4/SquareRoot.java b/src/com/github/pedrovgs/problem4/SquareRoot.java index 809da1e..580198a 100644 --- a/src/com/github/pedrovgs/problem4/SquareRoot.java +++ b/src/com/github/pedrovgs/problem4/SquareRoot.java @@ -16,81 +16,83 @@ package com.github.pedrovgs.problem4; /** + * 浠ュ弬鏁板舰寮忎紶鍏ユ暣鏁帮紝璁$畻骞虫柟鏍 + * ================================ * Given an integer passed as parameter, can you write a method to calculate the square root? * * @author Pedro Vicente G贸mez S谩nchez. */ public class SquareRoot { - private static final double DELTA = 0.1; + private static final double DELTA = 0.1; - /** - * Solution implemented to calculate the square root of a given number based on an iterative - * algorithm. - * - * First, we are going to find the first number witch square is greater than the number. Once we - * have that number we are going to apply a binary search between candidate and candidate +1. - * - * The complexity order in space terms of this algorithm is O(1) because we are not using any - * additional data structure. The complexity order in time terms is more difficult to calculate - * T(N) = T(N/2) + c where as N is step length. Which is 1 initially. 0.5 after that. 0.25 after that - * Stopping condition of this recurrence relation is dependant on delta. If it is 0, then time complexity is infinite - * So we won't be able to calculate the exact time complexity using master's theorem. - * Time complexity of this algorithm is inversly proportional to square root of Delta - * As square root is an irrational number for non square numbers. - * But here, it will be function of delta and precision of the variables used. Which is difficult to calculate. - * - */ - public float calculateSquareRootIterative(int number) { - //Search first candidate - float candidate = 1f; - while (candidate * candidate <= number) { - candidate++; - } - candidate--; - if (isGoodResultForSqrt(number, candidate * candidate)) { - return candidate; - } + /** + * 杩唬绠楁硶瀹炵幇 + * Solution implemented to calculate the square root of a given number based on an iterative + * algorithm. + *

+ * First, we are going to find the first number witch square is greater than the number. Once we + * have that number we are going to apply a binary search between candidate and candidate +1. + *

+ * The complexity order in space terms of this algorithm is O(1) because we are not using any + * additional data structure. The complexity order in time terms is more difficult to calculate + * T(N) = T(N/2) + c where as N is step length. Which is 1 initially. 0.5 after that. 0.25 after that + * Stopping condition of this recurrence relation is dependant on delta. If it is 0, then time complexity is infinite + * So we won't be able to calculate the exact time complexity using master's theorem. + * Time complexity of this algorithm is inversly proportional to square root of Delta + * As square root is an irrational number for non square numbers. + * But here, it will be function of delta and precision of the variables used. Which is difficult to calculate. + */ + public float calculateSquareRootIterative(int number) { + //Search first candidate + float candidate = 1f; + while (candidate * candidate <= number) { + candidate++; + } + candidate--; + if (isGoodResultForSqrt(number, candidate * candidate)) { + return candidate; + } - //Apply binary search. - float top = candidate + 1; - float bottom = candidate; - float newCandidate = (top + bottom) / 2; - float result = newCandidate * newCandidate; - while (!isGoodResultForSqrt(number, result)) { - if (result > number) { - top -= 0.1f; - } else { - bottom -= 0.1f; - } - newCandidate = (top + bottom) / 2; - result = newCandidate * newCandidate; + //Apply binary search. + float top = candidate + 1; + float bottom = candidate; + float newCandidate = (top + bottom) / 2; + float result = newCandidate * newCandidate; + while (!isGoodResultForSqrt(number, result)) { + if (result > number) { + top -= 0.1f; + } else { + bottom -= 0.1f; + } + newCandidate = (top + bottom) / 2; + result = newCandidate * newCandidate; + } + return Math.abs(newCandidate); } - return Math.abs(newCandidate); - } - /** - * Tail recursive approach to resolve this problem. This algorithm is based on a binary search, - * as - * the previous one, but implemented using a tail recursive approach. In space terms, the - * complexity order of this solution is O(1) and in time terms is similar to the other - * implementation. - * - * This public method uses a private method to hide the algorithm implementation. - */ - public float calculateSquareRootRecursive(int number) { - return sqrtRecursiveInner(number, 0, number); - } + /** + * Tail recursive approach to resolve this problem. This algorithm is based on a binary search, + * as + * the previous one, but implemented using a tail recursive approach. In space terms, the + * complexity order of this solution is O(1) and in time terms is similar to the other + * implementation. + *

+ * This public method uses a private method to hide the algorithm implementation. + */ + public float calculateSquareRootRecursive(int number) { + return sqrtRecursiveInner(number, 0, number); + } - private static float sqrtRecursiveInner(float n, float low, float high) { - float sqrt = (low + high) / 2; - float diff = sqrt * sqrt - n; - if (diff > DELTA) return sqrtRecursiveInner(n, low, sqrt); - if (-diff > DELTA) return sqrtRecursiveInner(n, sqrt, high); - return sqrt; - } + private static float sqrtRecursiveInner(float n, float low, float high) { + float sqrt = (low + high) / 2; + float diff = sqrt * sqrt - n; + if (diff > DELTA) return sqrtRecursiveInner(n, low, sqrt); + if (-diff > DELTA) return sqrtRecursiveInner(n, sqrt, high); + return sqrt; + } - private static boolean isGoodResultForSqrt(float number, float result) { - return Math.abs(result - number) < DELTA; - } + private static boolean isGoodResultForSqrt(float number, float result) { + return Math.abs(result - number) < DELTA; + } } diff --git a/src/com/github/pedrovgs/problem74/BubbleSort.java b/src/com/github/pedrovgs/problem74/BubbleSort.java index d8cb56e..0d49d86 100644 --- a/src/com/github/pedrovgs/problem74/BubbleSort.java +++ b/src/com/github/pedrovgs/problem74/BubbleSort.java @@ -18,43 +18,44 @@ import com.github.pedrovgs.sortingalgorithm.SortingAlgorithm; /** + * 缁欏畾鏁村舰鏁扮粍锛屼娇鐢ㄥ啋娉″鍏惰繘琛屾帓搴 + * ======================================== * Given an array full of integers implement a bubble sort algorithm to sort the content inside the * array. - * * @author Pedro Vicente G贸mez S谩nchez. */ public class BubbleSort extends SortingAlgorithm { - /** - * Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that - * repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps - * them if they are in the wrong order. The pass through the list is repeated until no swaps are - * needed, which indicates that the list is sorted. The algorithm, which is a comparison sort, is - * named for the way smaller elements "bubble" to the top of the list. Although the algorithm is - * simple, it is too slow and impractical for most problems even when compared to insertion - * sort. It can be practical if the input is usually in sort order but may occasionally have - * some out-of-order elements nearly in position. - * - * The complexity order of this algorithm in time terms is O(N^2) where N is equals to the number - * of elements in the input array. In space terms, the complexity order is O(1) because to solve - * this problem we are not using any auxiliary data structure. - */ - public void sort(int[] numbers) { - validateInput(numbers); + /** + * Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that + * repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps + * them if they are in the wrong order. The pass through the list is repeated until no swaps are + * needed, which indicates that the list is sorted. The algorithm, which is a comparison sort, is + * named for the way smaller elements "bubble" to the top of the list. Although the algorithm is + * simple, it is too slow and impractical for most problems even when compared to insertion + * sort. It can be practical if the input is usually in sort order but may occasionally have + * some out-of-order elements nearly in position. + *

+ * The complexity order of this algorithm in time terms is O(N^2) where N is equals to the number + * of elements in the input array. In space terms, the complexity order is O(1) because to solve + * this problem we are not using any auxiliary data structure. + */ + public void sort(int[] numbers) { + validateInput(numbers); - int length = numbers.length; - boolean swap = true; - while (swap) { - swap = false; - for (int i = 0; i < length - 1; i++) { - for (int j = 0; j < length - i - 1; j++) { - if (numbers[j] > numbers[j + 1]) { - swap(numbers, j, j + 1); - swap = true; - } + int length = numbers.length; + boolean swap = true; + while (swap) { + swap = false; + for (int i = 0; i < length - 1; i++) { + for (int j = 0; j < length - i - 1; j++) { + if (numbers[j] > numbers[j + 1]) { + swap(numbers, j, j + 1); + swap = true; + } + } + } } - } } - } } diff --git a/src/com/github/pedrovgs/problem76/InsertionSort.java b/src/com/github/pedrovgs/problem76/InsertionSort.java index cd50bfb..24b68b8 100644 --- a/src/com/github/pedrovgs/problem76/InsertionSort.java +++ b/src/com/github/pedrovgs/problem76/InsertionSort.java @@ -25,25 +25,26 @@ */ public class InsertionSort extends SortingAlgorithm { - /** - * Insertion sort is a simple sorting algorithm that is relatively efficient for small lists and - * mostly sorted lists, and often is used as part of more sophisticated algorithms. It works by - * taking elements from the list one by one and inserting them in their correct position into a - * new sorted list. In arrays, the new list and the remaining elements can share the array's - * space, but insertion is expensive, requiring shifting all following elements over by one. - */ - @Override public void sort(int[] numbers) { - validateInput(numbers); + /** + * Insertion sort is a simple sorting algorithm that is relatively efficient for small lists and + * mostly sorted lists, and often is used as part of more sophisticated algorithms. It works by + * taking elements from the list one by one and inserting them in their correct position into a + * new sorted list. In arrays, the new list and the remaining elements can share the array's + * space, but insertion is expensive, requiring shifting all following elements over by one. + */ + @Override + public void sort(int[] numbers) { + validateInput(numbers); - int i; - for (i = 1; i < numbers.length; i++) { - int tmp = numbers[i]; - int j = i; - while (j > 0 && numbers[j - 1] > tmp) { - numbers[j] = numbers[j - 1]; - j--; - } - numbers[j] = tmp; + int i; + for (i = 1; i < numbers.length; i++) { + int tmp = numbers[i]; + int j = i; + while (j > 0 && numbers[j - 1] > tmp) { + numbers[j] = numbers[j - 1]; + j--; + } + numbers[j] = tmp; + } } - } } diff --git a/src/com/offer/JumpStep.java b/src/com/offer/JumpStep.java index 8b0cadd..2a2c50f 100644 --- a/src/com/offer/JumpStep.java +++ b/src/com/offer/JumpStep.java @@ -3,11 +3,11 @@ import java.util.Scanner; /** - * 青蛙跳台阶问题:求斐波那契数列 - * <有一楼梯共m级,刚开始时你在第一级,> - * <若每次只能跨上一级或二级,要走上第m级,> - * <共有多少走法?> - * @author 杜伟 + * 闈掕洐璺冲彴闃堕棶棰橈細姹傛枑娉㈤偅濂戞暟鍒 + * <鏈変竴妤兼鍏眒绾э紝鍒氬紑濮嬫椂浣犲湪绗竴绾э紝> + * <鑻ユ瘡娆″彧鑳借法涓婁竴绾ф垨浜岀骇锛岃璧颁笂绗琺绾э紝> + * <鍏辨湁澶氬皯璧版硶锛> + * @author 鏉滀紵 */ public class JumpStep { diff --git a/src/com/offer/MinTotalInArr.java b/src/com/offer/MinTotalInArr.java index 36bbc81..2ed4e08 100644 --- a/src/com/offer/MinTotalInArr.java +++ b/src/com/offer/MinTotalInArr.java @@ -5,8 +5,8 @@ import java.util.Comparator; /** - * 给定整形数组,组合出最小值 - * @author 杜伟 + * 缁欏畾鏁村舰鏁扮粍锛岀粍鍚堟暟缁勫厓绱犵粰鍑烘渶灏忓 + * @author 鏉滀紵 */ public class MinTotalInArr { diff --git a/src/com/sohu/Test1.java b/src/com/sohu/Test1.java index 9611b03..f12d7d2 100644 --- a/src/com/sohu/Test1.java +++ b/src/com/sohu/Test1.java @@ -7,29 +7,29 @@ public class Test1 { - public static void main(String[] args) { - Scanner scanner = new Scanner(System.in); - int num = scanner.nextInt();// - int much = scanner.nextInt();// - char[] numChar = (num + "").toCharArray(); - List list = new ArrayList<>(); - List list2 = new ArrayList<>(); - for (int i = 0; i < numChar.length; i++) { - list.add(Integer.parseInt(numChar[i]+"")); - list2.add(Integer.parseInt(numChar[i]+""));//保存元素局 - } - Collections.sort(list); - for (int i = 0; i < much; i++) {//移除前much个元素 - list2.remove(list.get(i)); + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + int num = scanner.nextInt();// + int much = scanner.nextInt();// + char[] numChar = (num + "").toCharArray(); + List list = new ArrayList<>(); + List list2 = new ArrayList<>(); + for (int i = 0; i < numChar.length; i++) { + list.add(Integer.parseInt(numChar[i] + "")); + list2.add(Integer.parseInt(numChar[i] + ""));//淇濆瓨鍏冪礌灞 + } + Collections.sort(list); + for (int i = 0; i < much; i++) {//绉婚櫎鍓峬uch涓厓绱 + list2.remove(list.get(i)); // i++; // much--; - } + } // System.out.println(list2.toString()); - String returnString = ""; - for (int i = 0; i < list2.size(); i++) { - returnString += list2.get(i); - } - System.out.println(returnString); - } + String returnString = ""; + for (int i = 0; i < list2.size(); i++) { + returnString += list2.get(i); + } + System.out.println(returnString); + } } diff --git a/src/com/toutiao/HuiWenDecode.java b/src/com/toutiao/HuiWenDecode.java index 3f5f7d2..35583e9 100644 --- a/src/com/toutiao/HuiWenDecode.java +++ b/src/com/toutiao/HuiWenDecode.java @@ -3,8 +3,8 @@ import java.util.Scanner; /** - * 回文解码 - * @author 杜伟 + * 鍥炴枃瑙g爜 + * @author 鏉滀紵 */ public class HuiWenDecode { @@ -12,7 +12,7 @@ public static void main(String[] arg) { Scanner input = new Scanner(System.in); String _string = input.nextLine(); int a = input.nextInt(); - for (int i = 0; i < a; i++) {//执行a次操作,每次2个数字 + for (int i = 0; i < a; i++) {//鎵цa娆℃搷浣滐紝姣忔2涓暟瀛 int s1 = input.nextInt(); int s2 = input.nextInt(); _string = getString(_string, s1, s2); diff --git a/src/com/xiaomi/PhoneNum.java b/src/com/xiaomi/PhoneNum.java index 9b3c509..3b588ed 100644 --- a/src/com/xiaomi/PhoneNum.java +++ b/src/com/xiaomi/PhoneNum.java @@ -10,9 +10,9 @@ public static void main(String[] args) { int n = scanner.nextInt(); ArrayList list = new ArrayList<>(n); for (int i = 0; i < n; i++) { - list.add(scanner.nextLine());//所有分身放入链表 + list.add(scanner.nextLine());//鎵鏈夊垎韬斁鍏ラ摼琛 } - //输入完毕 + //杈撳叆瀹屾瘯 }