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;
                        }
                    }
                }
            }
        }

  • 相关阅读:
    【Matlab】去除图片周围空白区域(plot subplot)
    使用nbdev进行jupyter项目的开发
    如何绘制符合打印标准的图形
    如何使用Python完成视频的快速剪辑
    如何查看和修改论文图片的打印尺寸
    使用TMUX替代screen工具
    Emacs设置包管理器以及镜像
    Emacs的配置文件
    Emacs Windows的设置
    数据科学新的工具Julia
  • 原文地址:https://www.cnblogs.com/mikejay1234/p/1495558.html
Copyright © 2011-2022 走看看