This is the 26th day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021

Preface:

The previous article on blogger data started from a single linked list and missed a knowledge point, the sequence table of linear table, which is a separate knowledge point. In this article, we mainly explain the sequence table of linear table of data structure. Linear table is the simplest and most commonly used data structure. Linear table storage method in our programming used more, so it is necessary to understand, good words not to say, we began to learn, forgive the blogger reverse output knowledge!! Ha ha ha ha

Note: Sequential and linked lists are the main storage structures for linear lists.

Every day. Friday’s got to be Friday

Have what matter to say again next week, ha ha ha ha!!

1. Basic concepts of linear tables

Linear tables are the most basic, simplest, and most commonly used data structures. A linear list is a type of data structure. A linear list is a finite sequence of n data elements having the same properties. The relationship between data elements in a linear table is one-to-one, that is, all data elements are end to end except the first and last data elements (note that this applies only to most linear tables, not all. For example, a circular linked list is also a linear list at the logical level (the storage level is chained, but the last data element’s tail pointer points to the first node).

1.1 Definition of linear tables

A linear list is a type of data structure. A linear list is a finite sequence of n data elements having the same properties. A data element is an abstract symbol whose meaning varies from case to case. In a slightly complex linear table, a data element may consist of more than one data item. In this case, the data element is often called a record. A linear table containing a large number of records is also called a file. The number n in a linear table is defined as the length of the linear table. When n=0, it is called an empty table. Each data element has a defined location in a non-empty table. A linear list is a finite sequence of n (n≥0) data elements of the same type. When n=0, the table is empty and denoted as () or φ. When n>0, the logical representation of a linear table is (al, A2… Ai,… , an), can also be represented by the logical structure diagram shown below)

Table 2. The order

2.1 Definition of order table

A sequential list is a linear list stored in the computer memory in the form of an array. The sequential storage of a linear list means that each element in a linear list is stored in sequence by a set of storage units with contiguous addresses, so that the data elements in a linear list that are logically adjacent are stored in adjacent physical storage units. That is to say, the logical adjacency relation between data elements is reflected by the adjacency relation of physical storage of data elements. The linear table with sequential storage structure is usually called sequential table. Sequential table is to place the nodes of the table in sequence in a group of storage cells with contiguous addresses in computer memory. A sequential list is a linear list that is stored in computer memory in a sequential storage structure. It consists of contiguous storage units (arrays), each of which holds one element of a linear list. A sequence table is a structure that contains an array of variables, and this array is used to store values. The structure is called a sequence table.

Note: the blogger briefly explained the addition, deletion, change and check, in fact, it is not difficult for us to just look at the C language array application can.

2.2 Basic operation of sequence table

The operation of the sequential table and the operation of the array are similar, we have learned C language should be easy to understand, not very difficult, the blogger also do not do too much to end, C language good, this article is easy to understand, the blogger directly put the operation below:

#include <stdio.h> #define MaxSize 100 typedef struct { int data[MaxSize]; Int length; } SqList; Void InitList(sqList&l) // Since Lis passed back to the value parameter, use the reference type {l.length =0; Void DestroyList(SqList L) {} int GetLength(SqList L) {return l.length; // There is a length in the structure that is responsible for the statistics. O good} / / acquisition order form the value of the ith a int GetElem (SqList L, int, int & e) {if (I < 1 | | I > L.l ength) / / judgment on the effectiveness of the sequence table I return 0; else { e=L.data[i-1]; // I -1 return 1; Int Locate(SqList L,int x) {int I =0; while (i<L.length && L.data[i]! =x)// loop until the length is equal or not. If (I >= l.length) return(0); Else return(I +1); Int InsElem(SqList &L,int x,int I) {int j; If (I < 1 | | I > L.l ength + 1) / / invalid parameter I return 0; for (j=L.length; j>i; J --); j--); j--); j--); // I = 1, I = 1, I = 1; // I = 1, I = 1; // insert x l.length ++ at position I; Return 1; } int DelElem(SqList &L,int I) {int j; If (I < 1 | | I > L.l ength) / / invalid parameter I return 0; for (j=i; j<L.length; [J]; j++); j++); // select * from 'I'; // select * from 'I'; // The last one is in. We assign it 0; L.length--; Return 1; Void DispList(SqList L) {int I; for (i=0; i<L.length; Printf ("%d ", l.data [I]); printf("\n"); Void CreateList(SqList &L,int a[],int n) {int I,k=0; For (I =0; i<n; i++) { L.data[k]=a[i]; // add an element k++ to L; } l.length =k; Void swap(int &x,int &y) {int TMP =x; x=y; y=tmp; Void Swapmaxmin(SqList &L) {int I,maxi,mini; maxi=mini=0; for (i=1; i<L.length; i++) if (L.data[i]>L.data[maxi]) maxi=i; else if (L.data[i]<L.data[mini]) mini=i; swap(L.data[maxi],L.data[mini]); } int main() { int i; int e; SqList L; // define a sequence table L InitList(L); InsElem(L,6,1); // insert element 1 InsElem(L,4,2); // insert element 3 InsElem(L,8,3); // insert element 1 InsElem(L,2,4); // insert element 5 InsElem(L,3,5); // insert element 4 InsElem(L,1,6); Printf (" Print the created linear table :"); DispList(L); Printf (" Length of linear table :%d\n",GetLength(L)); i=3; GetElem(L,i,e); Printf (" d th element :%d\n", I,e); // Or the ith element e=1; Printf (" element %d is the %d element \n",e,Locate(L,e)); i=4; Printf (" delete element \n", I); DelElem(L,i); Printf (" linear list :"); DispList(L); DestroyList(L); return 0; }Copy the code

Conclusion:

The order of the linear table table, when we are learning C language should be exposed to, is what we are learning there are array structure, that is called order list, we are speak in bluntly array, that means the whole data structure of a bit gaudy, order form is very simple, we use is easy, learned a data structure of the portal, When the blogger wrote the picture, he would return to write this, to tell the truth, I do not want to write, but the blogger must write complete, good creation is not easy to like.