Data Structure | Chapter 1-5

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_43145926/article/details/98737505

I. Introduction

Define (a) a data structure and related concepts

  • Data: shows symbol objective things, in computer science refers to all symbols for input into the computer and a computer program process in general.
  • Element: the basic unit of data is normally processed as a whole in a computer program, such as trees.
  • Data objects: a set of data elements of the same nature, is a subset of the data, such as an integer data object.
  • Data structure: There is a collection of one or more data elements of a particular relationship to each other: a set of linear structure, a tree structure, mesh structure or a structure in FIG.
  • The physical structure / storage structure: sequential storage structure, Storage Structure
  • Logical structure

(B) abstract data types

  • Assignment, select statement, a loop statement, the end of the sentence, the input and output statements, comments, the basic functions, logic operations conventions

Time (three) algorithm complexity and space complexity

  • slightly

Second, the linear form

Define (a) and the basic operation of the linear form

  • Definition: the priority sequence of n data elements.

(Part two) in the linear form

1. sequential storage structure
#define LIST_INIT_SIZE 100 //线性表存储空间的初始分配量
#define LISTINCREMENT 10//线性表存储空间的分配增量
typedef struct{
	Elem *elem; //存储空间基地址
	int length;//当前长度
	int listsize; //当前分配的存储容量,以sizeof(ElemType)为单位
}SqList;
2. Storage Structure, circular linked list, doubly linked list

// single list / circular list

typedef struct LNode{
	ElemType data;
	struct LNode *next;
}LNode, *LinkList;

//Doubly linked list

typedef struct DuLNode{
	ElemType data;
	struct DuLNode *prior;
	struct DuLNode *next;
}DuLNode, *DuLinkList;
3. Application of the linear form
  • The lack of exercises, with respect to the linear form of additions and deletions to change search exercises

Third, stacks, queues

The basic concept of (a) of the stacks and queues

  • Stack: defining only insert or delete operation in the linear form of the trailer.
  • Queue: FIFO linear form, allowing only the insertion of one end of the table, at the other end to remove elements.

Sequential storage structure (II) of the stacks and queues

// store a stack of order

#define STACK_INIT_SIZE 100;//存储空间初始分配量
#define STACKINCREMENT ;//存储空间分配量
typedef struct {
	SElemType *base;
	SElemType *top; 
	int stcksize; //当前已分配的存储空间,以元素为单位
}SqStack;

// circular queue sequential storage structure

#define MAXQSIZE 100; //最大队列长度
typedef struct {
	QElemType *base; //初始化动态分配存储空间
	int front; //头指针,若队列不空,指向队列头元素
	int rear'//尾指针,若队列不空,指向队列尾元素的下一个位置
}SqQueue;

(C) memory stacks and queues chain structure

// queue chain store

typedef struct QNode{
	QElemType data;
	struct QNode *next;
}QNode,*QueuePtr;
typedef struct {
		QueuePtr front;
		QueuePtr rear;
}LinkQueue;

Application (iv) of the stacks and queues

  • Number conversion
    for an inputted arbitrary nonnegative integer in decimal, octal printouts its equivalent.
void conversion(){
	InitStack(s);
	scanf("%d",N);
	while(N)
	{
		Push(S,N%8);
		N=N/8;
	}
	while(! StackEmpty(s))
	{
		Pop(s,e);
		printf("%d",e);
	}
}
  • Brace matching test
  • Line editor
void LineEdit()
{
	InitStack(S);
	ch=getchar();//从终端接受第一个字符
	while(ch!=EOF)
	{
		while(ch!=EOF &&ch!='\n')
		{
			switch(ch)
			{
				case '#':Pop(S,c); break; //仅当栈非空时退栈
				case '@':CkearStack(S); break;//重置S为空栈
				default:Push(S,ch);break;//有效字符进栈,未考虑栈满情形
			}
			ch=getchar(); //从终端接收下一个字符
		}
		//将才栈底到栈顶的栈内字符传送至调用过程的数据区
		ClearStack(S);
		if(ch!=EOF) ch=getchar();
	}
	DestroyStack(S);
}
  • Maze solving
  • Expression evaluation
  • Fibonacci
  • Tower of Hanoi

Fourth, the string

(A) stores a series of various operations and

  • Strings: a finite sequence of zero or more characters, single quotation marks, such asa='BHKI'
  • String stores a fixed-length sequence
#define MAXSTRLEN 255 //用户可在255以内定义最大串长
typedef unsigned char SString[MAXSTRLEN+1];//0号单元存放串的长度
  • When the string is connected, not exceed the maximum length of the string is the correct result, the excess will be cut off directly
  • Heap-allocated storage representation
typedef struct {
	char *ch;//若是非空串,则按串长分配存储区,否则为NULL
	int length;//串长度
}HString;
  • String stores a chain block
#define CHUNKSIZE 80;//用户可定义的块大小
typedef struct Chunk{
	char ch[CHUNKSIZE];
	struct Chunk *next;
}Chunk;
typedef struct {
	Chunk *head, *tail;//串的头和尾指针
	int curlen;//串的当前长度
}LString;

(B) KMP algorithm

The push very detailed: https: //mp.weixin.qq.com/s/2JyZoy9pESrcd5hsGWLWgw
this to be watching: https: //blog.csdn.net/dark_cy/article/details/88698736

  • String search algorithm: used to check the position of a pattern string P appears in a text string S.
  • KMP algorithm needs to know handwritten code not yet understand

V. arrays and generalized table

Basic Concepts (a) of the array, representation and realization

Here Insert Picture Description

(B) compressing the memory matrix

  • If the distribution of the same element or zero element in the matrix of a certain law, then we call the special sub-matrix is ​​a matrix, otherwise known as a sparse matrix.
1. Special Matrices
2. sparse matrix

Definition (iii) and generalized table storage structure

Here Insert Picture Description

Guess you like

Origin blog.csdn.net/qq_43145926/article/details/98737505