Data structure - a learning summary

1. Mind Map

2. Study Notes

Linear table

1. Concept: The simplest, most commonly used linear structure.
2. The linear form of sequential storage structure

特点:逻辑上相邻,物理地址相邻。
     实现随机存储

Table 3. The linear chain structure

节点=数据元素+指针
数据元素:存放数据
指针:存放该节点的下一个元素的存储位置

4. Head interpolation

void CreateListF(LikList*& L, ElemType a[], int n)
{
	LinkList* s;
	int i;
	L = new LNode;
	L->next = NULL;//创建头节点,其next域设为NULL
	for (i = 0; i < n; i++) {//循环建立数据节点
		s = new LNode;
		s->data = a[i];//创建数据节点*s
		s->next = L->next;//将*s插在原开始节点之前,头节点之后
		L->next = s;
	}
}

Thinking: generating an empty list, the new node will continue in the linked list header, the node with the logical order of the list in reverse order.
The tail interpolation

void CreateListR(LinkList*& L, Elemtype a[], int n)
{
	LinkList* s, * r;
	int i;
	L = new LNode;//创建头节点
	r = L;//r始终指向尾节点,开始时指向头节点
	for (i = 0; i < n; i++) {//循环建立数据节点
		s = new LNode;
		s->data = a[i];//创建数据节点*s
		r->next = s;//将*s插入*r之后
		r = s;
	}
	r->next = NULL;//尾节点next域设置为NULL
}

Ideas: the linked list the new node is inserted into the end always need a tail pointer r. The order of the linked list node same logical order

Stack (LIFO)

Can only be inserted in the paragraph, delete the linear form.
1. According to the storage into the form: sequentially stack link stack.
2. Stack the order

1.初始化栈:栈顶元素为-1;s->top=-1。
2.判断栈是否为空:判断栈顶指针是否为-1。
3.进栈:元素进栈前要判断栈顶是否满。
4.出栈:先确定栈不为空。
5.取栈:先确定栈不为空。
*顺序栈四要素:
栈空条件:s->toop=-1;
栈满条件:s->top=MaxSize=-1;
进栈操作:s->top++;
出栈操作:s->top--;

3. Chain stack

1.栈的链式存储结构是单链表,包含指向下一个节点的指针域,数据域。
2.判断栈是否为空,只需要判断头节点next的值是否为空。
3.出栈:需先判断栈是否为空。
4.取栈:需先判断栈是否为空。
*链栈四要素:
栈空条件:s->next=NULL;
栈满条件:无需考虑;
进栈操作:将新数据节点插到头节点后;
出栈操作:取出头节点之后的节点数据域并删除;

Queue (FIFO)

Linear table can be inserted, and the other end of the section delete
1. According to the storage structure is divided into: the queues, the queue chain.
2. the queues

1.由一块连续的存储区域,和两个分别指向队头,队尾位置的变量组成。
2.队空:front=rear
3.队满:(rear+1)%MaxSize=front
4.入队:rear=(rear+1)%MaxSize
5.出队:front=(front+1)%MaxSize

3. Chain Team

1.单链表,由存储队列元素的数据节点,指向队头队尾指针的链队节点。
2.队空:q->rear=NULL
3.入队:将新的数据节点插到单链表表尾
3.出队:删除单链表的第一个数据节点

string

1. ordered sequence of zero or more characters, the operation target is the entire string, a character string processing only type
matching algorithm 2. string pattern
a.BF algorithm: keep back pointer, variable time complexity, higher.
b.KMP main string without backtracking algorithm pointer i, the pattern string to the right by a distance "sliding" as far as possible.

Recursion

1. The need to invoke self.
2. There must be recursive exports.

3. difficult problems, and solutions

Nextval knowledge of next function and
next array solving method:
the first one is 0 the next, the second next bit is 1, when solving the next value of each bit later, compared according to the previous one. First, the former with its next value corresponding to the content, and if equal, the next bit value is the next value of the former plus 1; if not equal, continue to look forward the next value corresponding to the contents of the previous next a value corresponding to the contents are compared on a bit until you find the content of an equal with the previous date, then the corresponding bit value of 1 is the value plus next demand; if found first and have not found a former equal content, then the value of the next bit is the demand 1.
* How to find the prefix and suffix
1. find a prefix, in addition to looking for all sub-last character string.
2. When looking suffix, in addition to looking for all child first character string.
There are strings P = abaabca, each common substring the maximum length of the prefix and suffix in the following table:

with a problem to explain the
pattern string S: abaabcac

Analysis next array
1. In general, a next first array is zero, the first 1 is two, the third bit pattern string when we observe the first two, is found a, B
2. in this case we need to do the longest matching prefixes and suffixes, the calculated maximum length of the common element, and then add 1, is the value of this bit next.
3. a third of the first two bits are a and B, the maximum length of the common element is 0, the value of the next bit is 1.
share nextval array
1. nextval requirements [I] value, we have to compare String [ i] and the value String [next [i]] of.
2. If the value String [I] and equal String [next [i]] characters, then nextval [i] is equal to the value of nextval [next [i]] of.
3. If the String [i] and String [next [i]] is not equal to one, then nextval [i] is equal to the value of next [i] value.

Guess you like

Origin www.cnblogs.com/zh18065294222/p/12588946.html