美文网首页
实训总结20171015

实训总结20171015

作者: 韩志俊 | 来源:发表于2017-10-15 16:09 被阅读0次

快速排序:

public class QuickSort {

public static int middle(int[] array, int left, int right) {

int temp = array[left];

while (left != right) {

while (right > left && array[right] > temp)

right--;

array[left] = array[right];

while (right > left && array[left] < temp)

left++;

array[right] = array[left];

}

array[right] = temp;

return right;

}

public static int[] sort(int[] a, int left, int right) {

if (left < right) {

int i = middle(a, left, right);

sort(a, left, i);

sort(a, i + 1, right);

}

return a;

}

public static void main(String[] args) {

int[] a = {11, 81, 27, 53, 42, 45, 6, 77, 178, 9, 70};

sort(a, 0, a.length - 1);

for (int i : a) {

System.out.print(i+" ");

}

}

}

冒泡排序:public classMaopao {

public static int[] sort(int[] a){

for(inti=0;i

inttemp = a[i];

for(intj=i+1;j

if(a[j]

a[i]=a[j];

a[j]=temp;

temp=a[i];

}

}

}

returna;

}

public static voidmain(String[] args) {

int[] a={11,15,8,18,22,25,45};

sort(a);

for(inti:a){

System.out.println(i+" ");

}

}

}

斐波那契数列:public classFibonacci {

public static  intf(intn){

if(n<=0)return0;

if(n<=1)return1;

if(n<=2)return1;

returnf(n-1)+f(n-2);

}

public static voidmain(String[] args) {

System.out.println(f(3));

}

}

队列排序:

public class Queue {

private Object[] objects;

private int size;

private int head;

private int end;

public Queue(int size) {

this.objects = new Object[size];

this.head = 0;

this.end = 0;

this.size = 0;

}

public void push(Object object) throws Exception {

if (this.size > objects.length)

throw new Exception("Queue is full!");

objects[end++] = object;

size++;

}

public Object pop() throws Exception {

if (this.size == 0)

//            return null;

throw new Exception("Queue is empty!");

if (head == objects.length)

this.head = 0;

size--;

return objects[head++];

}

public Object peek() throws Exception {

if (this.size == 0)

throw new Exception("Queue is empty!");

return objects[head];

}

public boolean isEmpty() {

return size == 0;

}

public boolean isFull() {

return size == objects.length;

}

public int getSize() {

return size;

}

}

堆排序:

public class Stack {

private Object[] objects;

private int head;

private int size;

public Stack(int size) {

objects = new Object[size];

this.head = 0;

this.size = 0;

}

public void push(Object object) throws Exception {

if (this.size == objects.length)

throw new Exception("this stack is full");

objects[head++] = object;

size++;

}

public Object pop() throws Exception {

if (size == 0)

throw new Exception("this stack is empty");

size--;

return objects[--head];

}

}

相关文章

  • 实训总结20171015

    快速排序: public class QuickSort { public static int middle(i...

  • 实训总结

    时光的表盘上,总有一些耀眼的时刻,标注着历史的进程。八周的实训时间转瞬即逝,所谓的期末就在岁末中画上了圆满的句号了...

  • 实训总结

    回顾这两个月实训经历,对学生来说,只是大学课程中一小段,但是对我来说影响深远。在这个过程中有问题也有收获。 在教学...

  • 6.6实训总结

    通过今天一下午的实训,我学到了很多东西,也让我对网络营销有了新的认知,孙振老师也带我们见识了大佬们对网络营销的各种...

  • 实训总结20170923

    数据仓库概述 什么是数据仓库? 创始人W.H.Inmon在《建立数据仓库》一书中对数据仓库的定义是:数据仓库就是面...

  • 实训总结20171103

    SSM Spring:业务层的框架 Spring mvc:开发web应用程序的模块model+view+contr...

  • 实训总结20170917

    hive介绍 基于Hadoop的一个数据仓库工具,构建于hadoop的hdfs和mapred之上,用于管理和查询结...

  • 实训总结20170916

    CREATE TABLE city( province_code INT, province_name strin...

  • 实训总结20171006

    Zookeeper 是一个分布式应用程序提供高性能协调服务的工具集合。 ZooKeeper本质上是一个分布式的小文...

  • 实训总结20170924

    MapReduce代码 Map过程 IntW...

网友评论

      本文标题:实训总结20171015

      本文链接:https://www.haomeiwen.com/subject/bejcuxtx.html