zoukankan      html  css  js  c++  java
  • 数据结构 Record

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace feng
    {
        class Program
        {
            static void Main(string[] args)
            {
                SequentialList list= new SequentialList ();
                Record Record0 = new Record ("林伟坤",09108004,"男",21,"计算机081班","健康");
                Record Record1= new Record ("减肥的",09108005,"男",21,"计算机081班","健康");
                Record Record2= new Record ("反对",09108006,"男",21,"计算机081班","健康");
                list.Add(Record0 );
                list.Insert(0,Record1 );
                list .Display ();
                Console.ReadKey();
            }
        }


        class Record
        {
            internal string Name;//名字
            internal int Number;//学号
            internal string Gender;//性别
            internal int Age;//年龄
            internal string Class;//班级
            internal string Health;//健康状况


            public Record(string name, int number, string gender, int age, string strClass, string health)
            {
                Name = name;
                Number = number;
                Gender = gender;
                Age = age;
                Class = strClass;
                Health = health;
            }
           
             public void Display()
            {
                Console.WriteLine ("姓名:"+Name+";学号:"+Number.ToString ()+";性别:"+Gender+";年龄:"+Age.ToString ()+";班级:"+Class+";健康状况:"+Health );
            }
       
        }


        class SequentialList
        {
            private Record[] m_Records;
            private int m_ListSize;
            private   int m_NumOfRecords;
            private const int m_InitListSize = 100;
            private const int m_ListIncrement = 10;
            public   SequentialList()
            {
                m_ListSize = m_InitListSize;
                m_Records = new Record[m_ListSize];
                m_NumOfRecords = 0;

            }

            public   bool Empty()
            {
                if (m_NumOfRecords == 0)
                    return true;
                else
                    return false;
            }


           
            public void Add(Record record)
            {
                CheckIncreaseSpace();
                m_NumOfRecords++;
                m_Records[m_NumOfRecords - 1] = record;

            }

            private   void CheckIncreaseSpace()
            {
                if (m_ListSize == m_NumOfRecords)
                {
                    Record[] records = new Record[m_ListSize + m_ListIncrement];
                    for (int i = 0; i < m_NumOfRecords; i++)
                    {
                        records[i] = m_Records[i];
                    }
                    m_Records = records;
                }
            }

            public void Display()
            {

                if (m_NumOfRecords == 0)
                    Console.WriteLine("This list is empty!");
                else
                    for (int i = 0; i < m_NumOfRecords; i++)
                        m_Records[i].Display();
            }

            public int Length()
            {
                return (m_NumOfRecords);
            }

            public void Insert(int loacation, Record record)
            {
                if ((loacation < 0) || (loacation > m_NumOfRecords))
                {
                    Console.WriteLine("Conn't print!");
                    return;
                }
                else
                {
                    CheckIncreaseSpace();
                    for (int i = m_NumOfRecords; i > loacation; i--)
                    {
                        m_Records[i]=m_Records [i-1];

                    }
                    m_Records[loacation] = record;
                    m_NumOfRecords++;
                }
            }

        }
     
    }

    学数据结构最基本的程序

  • 相关阅读:
    JavaScript二进制数据序列化和反序列化
    三维变换矩阵推导笔记
    如何制作一款“有毒”的游戏
    如何使用visual studio将你的程序打包成安装包
    游戏设计模式系列(三)—— 策划变心太快?也许可以使用组合
    使用LayaAir解析xml文件
    游戏设计模式系列(二)—— 适时使用观察者模式,解耦你的代码
    游戏设计模式系列(一)—— 单线逻辑&&数据驱动,搞定最容易卡死的结算界面
    vs2010 win32程序中 sqlserver 2008 express的简单使用 (C++)
    UVALive 6529
  • 原文地址:https://www.cnblogs.com/linsond/p/1701362.html
Copyright © 2011-2022 走看看