【Data Structure】------类型定义
来源:互联网 发布:验证身份证18位数的js 编辑:程序博客网 时间:2024/06/14 23:37
【Data Structure】------类型定义
小编今天来和你一起分享一下,类型的定义,在数据结构中有表,队,栈和链,他们的定义分别是怎样的?
为什么要定义类型?
通俗的说就是给数据分配一定的恐惧,想想,如果不事先声明类型的话,也就不好怎么确定分配多少内存来存储数据了。
怎么定义?具体的表、队、栈和链的定义:
1,顺序表的定义:
Constint Maxsize=20; //预先定义一个足够大的常数Typedef struct {DataType data[Maxsize]; //存放数据数组Int length; //顺序表的实际长度} SeqList; //顺序表类型名:SeqListSeqList L; //定义L为一个顺序表
例子:
Cons tint Maxsize=7;Typedef struct{ Int num;Char name[8];Char sex[2];Int age;Int score;}DataTypeTypedef struct{ DataType data[Maxsize];Int length;}SeqList;SeqList student;
2,顺序队列类型定义:
Cons tint maxsiz=20;Typedef struct seqqueue{ DataType data[maxsize];Int front, rear;}SeqQue;SeqQue SQ;
3,顺序栈:
Cons tint maxsize=6;Typedef struct seqstack{DataType data[Maxsize];Int} SeqStk;
4,单链表类型定义:
Typedef struct node{DataType data; //数据域Struct nod* next; //指针域}Node, *LinkLIst;
例子:
Typedefstruct{Int num; //学号Char name[8]; //姓名Char sex[2]; //姓别Int age;//年龄Int score;//入学成绩}DataType//定义结点类型Typedef Struct nod{ Datatype data; //数据域,代表上面多有的数据值的Struct node *next; //指针域}Node,*LinkList; //Node是链表节点的类型LinkList head;
5,栈的定义:
Cons tint stacksize=40;Typedef struct SQstack{Int data[stacksize];Int top;}SQStackTp;
6,链栈定义:
typedefstruct node{ DataType data;Struct node * next;} LkStk;
规律总结:
对于这个类型定义分为两个链式的和非链式的,链式的有一个开始容量的定义,非链式的没有。
Constint Mastsize=100; //非链式的一个定义Typedef struct node //node 是内部的一个,下面将去用{DataType data; //数据域Struct node*next;(struct nod * front,*next;) //分为单链和双链,双链的画有头尾指针}Node, * LinkList; //Node是下一个struct 的数据类型,*LinkList是整个表的头指针。
0 0
- 【Data Structure】------类型定义
- Data Structure
- Data structure
- Data Structure
- Data structure
- Data structure
- data structure
- Data Structure
- Data structure
- Data Structure
- Data Structure
- Data Structure
- Data Structure
- Data structure alignmentData structure alignment
- Finish Data Structure Examination
- 【OPENGL】DEVMODE data structure
- Critical Data Structure -- sk_buff
- Data Structure数据结构
- mysql安装步骤
- lightoj 1125 - Divisible Group Sums
- laravel基础知识-框架目录文件介绍
- java中的socket编程
- C#调用C++dll方法,char*类型之间的传递
- 【Data Structure】------类型定义
- mysql的约束
- C#控制台基础 自定义类不同实例之间的赋值(引用传递的一个示例)
- 欢迎使用CSDN-markdown编辑器
- Linux学习笔记之RHEL6修改root密码
- Flask Web 开发 博客文章_5
- 《江湖X》开发笔谈——服务器技术架构
- RuntimeError 可能发生的情况
- 将构件发布到maven