C\# 데이터 구조 회고 순서 표
먼저 통용 되 는 인터페이스 클래스 를 정의 합 니 다 (인터페이스 클래스 의 방법 을 실현 합 니 다).
namespace DataStructureLearning.Interface
{
    //        (   、  )
    public interface IListDataStructure<T>
    {
        int GetLength(); //   
        void Clear(); //    
        bool IsEmpty(); //         
        void Append(T item); //    
        void Insert(T item, int i); //    
        T Delete(int i); //   i     
        T GetElem(int i); //   i   
        int Locate(T value); //         value     
        void DisplayItems();//  
    }
}  이어서 순서 표 실체 클래스 구현:
몇 가지 중요 한 조작 만 기억 하면:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataStructureLearning.Interface;
namespace DataStructureLearning.ImplementClass
{
    //          
    public class LinearList<T> :IListDataStructure<T>
    {
        #region ---     -------
        private int maxSize;
        private int lastIndex;
        private T[] data;
        #endregion
        #region -------  --------
        //   
        public T this[int index]
        {
            get
            {
                return data[index];
            }
            set
            {
                data[index] = value;
            }
        }
        public int LASTINDEX
        {
            get
            {
                return lastIndex;
            }
        }
        public int MAXSIZE
        {
            get
            {
                return maxSize;
            }
        }
        #endregion 
        #region ------    -----
        public LinearList(int size)
        {
            maxSize=size;
            lastIndex=-1;
            data=new T[size];
        }
        #endregion
        #region ------    -----
        //       
        public int GetLength()
        {
            return lastIndex+1;
        }
        //  
        public void Clear()
        {
            lastIndex=-1;
        }
        //         
        public bool IsEmpty()
        {
            if (lastIndex == -1)
            {
                return true;
            }
            else
            {
                return false;
            }
        } 
        //    
        public bool IsFull()
        {
            if(maxSize==lastIndex+1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        //        
        public void Append(T item)
        {
            if(IsFull())
            {
                Console.WriteLine("     !");
                return;
            }
                data[++lastIndex] = item;
        }
        //      i                
        public void Insert(T item, int i)
        {
            if (IsFull()==true)
            {
                Console.WriteLine("     !");
                return;
            }
            if(i<1 || i>lastIndex+2)
            {
                Console.WriteLine("      ");
                return;
            }
            if (i == lastIndex + 2)
            {
                data[lastIndex+1] = item;
            }
            else
            {
                for (int j = lastIndex; j>= i-1; --j)
                {
                    data[j + 1] = data[j];
                }
                data[i-1] = item;
            }
            ++lastIndex;
        }
        //       i                  
        public T Delete(int i)
        {
            T tmp = default(T);
            if (IsEmpty())
            {
                Console.WriteLine("     !");
                return tmp;
            }
            if (i < 1 || i > lastIndex+1)
            {
                Console.WriteLine("           ");
                return tmp;
            }
            if (i == lastIndex+1)
            {
                tmp = data[lastIndex--];
            }
            else
            {
                tmp = data[i-1];
                for (int j = i; j <= lastIndex; ++j)
                {
                    data[j] = data[j + 1];
                }
            }
            --lastIndex;
            return tmp; 
        }
        //       i     
        public T GetElem(int i)
        {
            if (IsEmpty() || (i<1) || (i>lastIndex+1))
            {
                Console.WriteLine("            ");
                return default(T);
            }
            return data[i-1];
        }
        //         value     
        public int Locate(T value)
        {
            if(IsEmpty())
            {
                Console.WriteLine("     !");
                return -1;
            }
            int i = 0;
            for (i = 0; i <= lastIndex; ++i)
            {
                if (value.Equals(data[i]))
                {
                    break;
                }
            }
            if (i > lastIndex)
            {
                return -1;
            }
                return i;
        }
        //     
        public void Reverse(LinearList<int> L)
        {
            int tmp = 0;
            int len = L.GetLength();
            for (int i = 0; i<= len/2; ++i)
            {
                tmp = L[i];
                L[i] = L[len - i];
                L[len - i] = tmp;
            }
        }
        //     
        public void DisplayItems()
        {
            for (int j = 0, l = data.Length; j < l; j++)
            {
                Console.Write(data[j]+"\t");
            }
        }
        //           
        public LinearList<int> Merge(LinearList<int> La, LinearList<int> Lb)
        {
            LinearList<int> Lc = new LinearList<int>(La.maxSize + Lb.maxSize);
            int i = 0;
            int j = 0;
            int k = 0;
            //          
            while ((i <= (La.GetLength()-1))&& (j <= (Lb.GetLength()-1)))
            {
                if (La[i] <Lb[j])
                {
                    Lc.Append(La[i++]);
                }
                else
                {
                    Lc.Append(Lb[j++]);
                }
            }
            //a        
            while (i <= (La.GetLength() - 1))
            {
                Lc.Append(La[i++]);
            }
            //b        
            while (j <= (Lb.GetLength() - 1))
            {
                Lc.Append(Lb[j++]);
            }
            return Lc;
        }
    }
    #endregion 
}  순서 표 단순 응용 클래스 (쓸데없는 짓 인 것 같 습 니 다):
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataStructureLearning.ImplementClass;
namespace DataStructureLearning.DataStructrueApplyClass
{
    public class LinearListApply
    {
        public LinearListApply(int size)
        {
            linear = new LinearList<int>(size);
        }
        public LinearList<int> linear;
        public void ExeAppend(int value)
        {
            linear.Append(value);
        }
        public void ExeInsert(int index,int value)
        {
            linear.Insert(index, value);
        }
        public void ExeDispalyList()
        {
            linear.DisplayItems();
        }
    }
}
  순서 표 의 간단 한 테스트:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataStructureLearning.DataStructrueApplyClass;
using DataStructureLearning.ImplementClass;
namespace DataStructureLearning
{
    class Program
    {
        static void Main(string[] args)
        {
            #region -----      ------
            LinearListApply linearApply = new LinearListApply(8);
            linearApply.ExeAppend(1);
            linearApply.ExeAppend(9);
            linearApply.ExeAppend(5);
            linearApply.ExeAppend(2);
            linearApply.ExeAppend(7);
            Console.WriteLine("      :");
            linearApply.ExeDispalyList();
            Console.WriteLine();
            Console.WriteLine("         2     :");
            linearApply.ExeInsert(2, 3);
            linearApply.ExeDispalyList();
            Console.WriteLine();
            linearApply.linear.Delete(3);
            Console.WriteLine("      3           :");
            linearApply.ExeDispalyList();
            Console.WriteLine();
            Console.WriteLine("   5    :");
            Console.WriteLine(linearApply.linear.GetElem(5));
            #endregion
      #endregion
      Console.ReadLine();
        }
    }
    #endregion
}  소결:
선형 표 는 가장 간단 하고 기본 적 이 며 가장 자주 사용 하 는 데이터 구조 로 선형 표 의 특징 은 데이터 요소 간 에 일대일 의 선형 관계 가 존재 한 다 는 것 이다. 즉, 첫 번 째 와 마지막 데이터 요 소 를 제외 하고 나머지 데이터 요 소 는 모두 있 고 하나의 직접적인 전구 와 직접적인 후계 만 있다 는 것 이다.
추가 확장 인덱스:
색인 기 (Indexer) 는 C\# 가 도입 한 새로운 유형의 구성원 으로 대상 이 배열 처럼 편리 하고 직관 적 으로 인용 할 수 있 도록 한다.색인 기 는 앞에서 말 한 속성 과 매우 유사 하지만, 색인 기 는 매개 변수 목록 이 있 을 수 있 으 며, 인 스 턴 스 대상 에 만 작용 할 수 있 으 며, 클래스 에 서 는 직접 작용 할 수 없습니다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
정수 반전Udemy 에서 공부 한 것을 중얼거린다 Chapter3【Integer Reversal】 (예) 문자열로 숫자를 반전 (toString, split, reverse, join) 인수의 수치 (n)가 0보다 위 또는 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.