数据结构:绪论

数据结构

定义

  • 组织数据–存储数据–操作数据(增添删改查)–代码实现
  • 数据结构是研究数据的逻辑结构,存储结构以及它们之间的关系,并对这种结构定义相适应的运算,设计出相应的算法

基本概念与术语

  • 数据:指所有能输入计算机中并被计算机程序处理的符号集合

  • 数据元素:数据的基本单位,也称为结点,顶点,记录

  • 数据项:具有独立含有的最小标识单位
    数据由数据元素组成,数据元素由数据项组成

  • 逻辑结构:对数据之间逻辑关系的描述
    在这里插入图片描述

  • 存储结构:逻辑结构在计算机存储器中的实现,即数据在计算机中的存放方式
    顺序:利用数组对数据进行存储
    链式:利用指针对数据进行存储
    索引:利用索引表来定位数据的存储
    散列:利用散列函数,根据数据元素的关键字来定位数据的存储

  • 数据类型:是数据的取值范围和对数据进行操作的总和

  • 抽象数据类型

构建一个矩形
ADT Rectangle is
	Data
		float Length
		float Width
	Operations
		Constructor
			Initial Values:构造举行时赋长和宽的值
			Press:初始化对象,给矩形的长和宽赋值
		SetLength
		SetWidth
		GetArea
		GetPerimeter
using System;

namespace ConsoleApp1
{
    class Rectangle 
    {
        //Data
        public float Width;
        public float Length;
        //Operations
        public Rectangle(float w,float l) 
        {
            Width = w > 0 ? w : 0;
            Length = l > 0 ? l : 0;
        }
        public void SetWidth(float w) 
        {
            Width = w > 0 ? w : 0;
        }
        public void SetLength(float l) 
        {
            Length = l > 0 ? l : 0;
        }
        public float GetArea() 
        {
            return Width * Length;
        }
        public float GetPrimeter() 
        {
            return (Width + Length) * 2;
        }

    }
    class Program
    {
        static void Main(string[] args)
        {
            Rectangle rect = new Rectangle(3.1f,2);
            Console.WriteLine(rect.GetArea());
            Console.WriteLine(rect.GetPrimeter());
            rect.SetLength(5.0f);
            rect.SetWidth(4.0f);
            Console.WriteLine(rect.GetArea());
            Console.WriteLine(rect.GetPrimeter());
        }
    }
}
//
6.2
10.2
20
18
数组找值
using System;

namespace ConsoleApp2
{
    class Program
    {
        static int Find(int[] A, int k) 
        {
            for (int i = 0; i < A.Length; i++) 
            {
                if (A[i] == k)
                    break;
                return i == A.Length ? -1 : i;
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

算法

定义

  • 为了解决某类特定问题而提出的一组有穷规则,即以某些值或值得集合为输出得一系列运算步骤
发布了73 篇原创文章 · 获赞 2 · 访问量 3157

猜你喜欢

转载自blog.csdn.net/soulmate______/article/details/105114521