【Postgraduate entrance examination or self-study data structure 2.1】——Linear table (definition of linear table, basic operation of linear table)

Offline notes:
Link: https://pan.baidu.com/s/1e-goeFpFw4CwxYoKhBsCtA
Extraction code: eiyq

1. Definition of linear table

A linear table is a 相同finite number of n (n≥0) data elements with data types 序列, where n is the length of the table, and when n = 0, the linear table is one 空表. If the linear table is named with L, it is generally expressed as

Same: each data element occupies the same space
Sequence: ordered

L = (a1, a2,…, ai, ai + 1,…, an)

Several concepts:
ai is the "i-th" element in the linear table, 位序
a1 in the linear table is 表头元素; an is 表尾元素.
Except for the first element, each element has and only one 直接前驱; except for the last element, each element has and only one 直接后继.

Note: 位序starting from 1 array subscript starting from 0

Insert picture description here

2. Basic operation of linear table

The basic operation of the linear table is the three elements of the data structure-"operation"

Why implement basic operations on data structures?
①For teamwork programming, the data structure you define should be easily used by others (encapsulation)
②Package common operations/calculations into functions to avoid duplication of work and reduce the risk of errors

Basic operation

  • InitList (& L): 初始化表. Construct an empty linear table L and allocate memory space.
  • DestroyList (& L): 销毁操作. Destroy the linear table and release the memory space occupied by the linear table L.
  • ListInsert (& L, I, E): 插入操作. Insert the specified element e at the i-th position in the table L.
  • ListDelete (& L, I, E &): 删除操作. Delete the element at the i-th position in the table L, and use e to return the value of the deleted element.
  • LocateElem (L, E): 按值查找操作. Find the element with the given key value in table L.
  • GetElem (L, I): 按位查找操作. Get the value of the element at the i-th position in the table L.

Other common operations:

  • The Length 求表长(L): . Returns the length of the linear table L, that is, the number of data elements in L.
  • Printlist 输出操作(L): . All the element values ​​of the linear table L are output in the order of front and back.
  • Empty 判空操作(L): . If L is an empty list, return true, otherwise return false.

Tips: ①Operate
data (memory ideas) —— create sales, add, delete, modify and check
② Definition of C language function—— <return value type> function name (<parameter 1 type> parameter 1, <parameter 2 type> parameter 2, ……)
③In actual development, other basic operations can be defined according to actual needs.
④The function name and parameter form and naming can be changed (Reference: Yan Weimin version "Data Structure")
⑤When should the reference "&" be passed in —— The result of parameter modification needs to be "brought back"

When to pass in the parameter reference "&" —— The modified result of the parameter needs to be "brought back"
Insert picture description here

3 Highlights of this section

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_38454176/article/details/105752006