数据结构 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++;
            }
        }

    }
 
}

学数据结构最基本的程序

原文地址:https://www.cnblogs.com/linsond/p/1701362.html