From 4be01831c814839e67a0b81b60d377564d41c81b Mon Sep 17 00:00:00 2001 From: jlhde123 <472327024@qq.com> Date: Tue, 14 Mar 2017 14:43:37 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=BF=AB=E6=8E=92=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=202=E3=80=81=E5=BE=AA=E7=8E=AF=E9=98=9F=E5=88=97=E7=AE=80?= =?UTF-8?q?=E5=8D=95=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/jlh/viewer/algorithm/MQueue.java | 67 +++++++++++++++++++ .../com/jlh/viewer/algorithm/QuickSort.java | 48 +++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 jlh/src/main/java/com/jlh/viewer/algorithm/MQueue.java create mode 100644 jlh/src/main/java/com/jlh/viewer/algorithm/QuickSort.java diff --git a/jlh/src/main/java/com/jlh/viewer/algorithm/MQueue.java b/jlh/src/main/java/com/jlh/viewer/algorithm/MQueue.java new file mode 100644 index 0000000..dd295d1 --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/algorithm/MQueue.java @@ -0,0 +1,67 @@ +package com.jlh.viewer.algorithm; + +import java.util.Arrays; + +/** + * Created by jlh + * On 2017/3/14 0014. + */ +public class MQueue { + private Integer[] datas; + private int front=0; + private int back=0; + private int store=0; + public MQueue(int size) { + this.datas = new Integer[size]; + } + public boolean push (int d){ + if (!isFull()) { + datas[back]=d; + back=(back+1)%datas.length; + store++; + return true; + } + return false; + } + public Integer pop (){ + if (!isEmpty()){ + store--; + Integer result=datas[front]; + front=(front+1)%datas.length; + return result; + } + return null; + } + + public boolean isEmpty(){ + return store==0?true:false; + } + + public boolean isFull(){ + if (store==datas.length) + return true; + return false; + } + + @Override + public String toString() { + return "MQueue{" + + "datas=" + Arrays.toString(datas) + + ", front=" + front + + ", back=" + back + + ", store=" + store + + '}'; + } + + public static void main(String[] args) { + MQueue mQueue = new MQueue(4); + for (int i=0;i<100;i++){ + if (!mQueue.push(i)){ + mQueue.pop(); + mQueue.push(i); + } + System.out.println(mQueue); + } + + } +} diff --git a/jlh/src/main/java/com/jlh/viewer/algorithm/QuickSort.java b/jlh/src/main/java/com/jlh/viewer/algorithm/QuickSort.java new file mode 100644 index 0000000..b64a45b --- /dev/null +++ b/jlh/src/main/java/com/jlh/viewer/algorithm/QuickSort.java @@ -0,0 +1,48 @@ +package com.jlh.viewer.algorithm; + +import java.util.Random; + +/** + * Created by jlh + * On 2017/3/14 0014. + */ +public class QuickSort { + public void reslove (int []datas,int l,int r){ + if (datas.length==0||l>=r) + return ; + int key= datas[l]; + int st= l; + int ed= r; + while (stst && datas[ed]>=key){ + ed--; + } + datas[st]=datas[ed]; + //此处是否有等于号无所谓,因为只要下个while循环至少能跳过那个交换后的值即可 + while (st