zoukankan      html  css  js  c++  java
  • 算法实习一

    最近我寝室一位同事遇到一些算法上的问题,顺便也让自己来练练手,写些算法和数据结构:自从大学毕业后,好久没碰了 特拿来回顾下

    自己写了简单的冒泡,为方便初始化的数组的大小都是用了方法写,没有用属性写,所以有点违反一点点原则了,嘿嘿嘿

     class SortList
        {
            private int[] listA;
            private int range;

            private int buttom;

            public void initList(int size)
            {
                listA= new int[size];
                range = size - 1;
                buttom = 0;
            }
            public void insert(int item)
            {
                listA[buttom] = item;
                buttom++;
            }

            public void printf()
            {
                for (int i = 0; i <= range; i++)
                {
                    Console.WriteLine(listA[i] + "");
                }
                Console.ReadLine();
            }

            //冒泡法
            public void BubbleSort()
            {
                int temp;
                for (int j = range; j > 0; j--)
                {
                    for (int i = 0; i < j; i++)
                    {
                        if (listA[i] > listA[i + 1])
                        {
                            temp = listA[i];
                            listA[i] = listA[i + 1];
                            listA[i + 1] = temp;
                        }
                    }
                }
            }
        }

  • 相关阅读:
    软能力
    git 使用命令
    jQuery插件stickup.js 源码解析初步
    HTML不常用的标签
    HTML笔记
    can't load XRegExp twice in the same frame
    IE8 不支持Date.now()
    href="#" href="javascript:void(0);" href="###"
    前端源码-部分资源
    javascript笔记
  • 原文地址:https://www.cnblogs.com/mikejay1234/p/1495558.html
Copyright © 2011-2022 走看看