-
The creation sequence table is as follows:
by the array element a[0..n-1] to create a sequential table l. Each element in a is placed sequentially in a sequential table, and n is assigned to the length field of the sequential table. The algorithm is:
int i=0, k=0;
l = (sqlist *)malloc(sizeof(sqlist));Allocate space to store linear tables.
while(il->data[k] = a[i];
k++;i++;
l->length = k;Sets the actual length of the linear table to k (i.e., the length n of a).
-
In fact, when you write the basic operation of a linear table, you describe it in terms of arrays (linear tables).
typedef struct arraylist;linear table void initlist(arraylist *l);
void destroylist(arraylist *l);
int *getelem(arraylist *l, int i);
int listinsert(arraylist *l, int i, int e);
int listdelete(arraylist *l, int i);
-
If you fix this input order, you can set an array first. The data can be entered sequentially in a loop, with -1 as the input termination condition.
-
Definition of a linear table
A linear table is a linear structure, the characteristics of a linear structure are that there is a linear relationship between data elements, data elements are arranged one after another, the type of data elements in a linear table is the same, or a linear table is a linear structure composed of the same type of data elements, in practical problems, there are many examples of linear tables, such as a student information table is a linear table, and the type of data elements in the table is the student type; A string is also a linear table, the data elements in the table are of type character, and so on.
In summary, linear tables are defined as follows.
A linear table is a finite sequence of n(n>= data elements of the same data type, usually denoted as.
a a … ai ai ai+ …an)
where n is the length of the table and n= is called an empty table.
There is a sequential relationship between adjacent elements in the table: ai is called the direct predecessor of ai, ai+ is called the direct successor of ai, that is, for ai, when i= n, there is and only one direct predecessor ai, when i= n, there is and only one direct successor ai+, and a is the first element in the table, it has no predecessor, and an is the last element, and there is no successor.
It should be noted that ai is a data element with an ordinal number of i (i= ...n) Usually we abstract its data type as datatype, datatype, depending on the specific problem, for example, in the student information table, it is a user-defined student type; In strings, it is the character type; Wait a minute.
lishixinzhi/article/program/sjjg/201311/23935
-
Characteristics of linear structureThere is a unique data element called the first There is a unique data element called the last One Except for the first One Each data element in the collection has only one predecessor Except for the last One Each data element in the collection has only one successor.
Definition of a linear tableA linear list is a finite sequence of n(n>) data elements of the same nature, denoted as (a, a, a...).an) The number of data elements in the table n is defined as the length of the linear table The table n= is called an empty table, that is, the linear table does not contain any data elements, and the number of masking elements Two types of storage structures for linear tables The state sequential storage Bimin structure (sequential table) The chain storage structure (linked list).Operations on linear tables
lishixinzhi/article/program/sjjg/201311/23826
-
Initial Condition Linear Table l exists.
Operation result: Finding the data element with value x in table l, and the result returns the ordinal number or address of the element whose value x appears for the first time in l, which is called the search success; Otherwise, a data element with value x is not found in l and a special value is returned, indicating a failed lookup.
Insert operation insert list(l i x).
Initial condition: Linear table l exists, the insertion position is correct, and the table length before insertion is (i<=n+ n is the length of the table before insertion).
Operation Result **Insert a new element with a value of x in the ith position of the sex table l, so that the sequence number of the data element with the original serial number i i+ n becomes i+ i+ n+ after insertion table length = original table length +
Delete list(l i).
Initial condition Linear table l exists <=i<=n
Result **Delete the data element with the ordinal number i in Table L After deleting, the element with the ordinal number i+ i+ n becomes the ordinal number i i + n The new table length = the original table length.
It should be clarified.
The basic operations on a data structure are not all of its operations, but some commonly used basic operations, and each basic operation may also derive a series of related operations according to different storage structures when it is implemented, such as the noisy search of linear tables, and there will be serial number searches in the chain storage structure; It is impossible and unnecessary to define all of its operations, and after the reader has mastered the basic operations on a certain data structure, the other operations can be implemented through the basic operations, or they can be implemented directly.
The linear table L defined in the above operations is only an abstract linear table at the level of logical structure, and its storage structure is not yet involved, so each operation cannot write a specific algorithm in a specific programming language at the level of logical structure, and the implementation of the algorithm can only be achieved after the storage structure is established.
lishixinzhi/article/program/sjjg/201311/23934
-
In a data structure, a linear structure refers to a one-to-one linear relationship between elements, i.e., each element has only one direct precursor and one direct successor. Linear structures mainly include the following:
1.Arrays: Arrays are the simplest linear structure, and the elements are stored continuously in memory, and the meta-silver rutin in them can be accessed by subscripts. Arrays are very efficient to query and modify, but inserts and deletes are relatively slow.
2.Linked lists: Linked lists are made up of several nodes, each containing data and a pointer to the next node. Insert and delete linked lists are very efficient, but queries and modifications require traversing the entire linked list.
3.Stack: A stack is a linear structure of a cover macro that can only be inserted and deleted at the top of the stack.
4.Queue: A queue is a first-in, first-out (FIFO) linear structure that can only insert elements at the end of the queue and delete elements at the head of the queue.
5.Heap: A heap is a special tree structure that satisfies the value of each node greater than or equal to (or less than equal to) the value of its child nodes. Heaps are typically used to implement data structures such as priority queues.
The above linear structures have their own advantages and disadvantages, and choosing the appropriate data structure according to specific application scenarios and needs can improve the efficiency and performance of the program.
-
1. Definition of linear tables.
1.Definition. A linear table is a finite sequence of n(n 0) data elements of the same data type. where n is the length of the table, and when n=0, the linear table is an empty table. If a linear table is named with l, it is generally expressed as.
l=(a1,a2…ai…an)
where a1 is the only first data element, also known as the header element; an is the only last data element, also known as the footer element.
2.Logical properties.
With the exception of the first element, each element has one and only one direct precursor. Each element has one and only one direct successor except the last element.
3.Features of linear tables.
1) The number of elements in the table is limited;
2) The elements in the table have a logical order, and the order of each element in the sequence has its order;
3) The elements in the table are all data elements, and each element is a single element (a single data item);
4) The data type of the elements in the table is the same, that is, each element occupies the same size of storage space;
5) The elements in the table are abstract, and only the logical relationship between the elements is discussed, without considering what the elements represent.
Note: A linear table is a logical structure that represents a one-to-one adjacency between elements. Sequential tables and linked lists are storage structures, not the same concept!
Second, the basic operation of linear tables.
The most basic operation: add, delete, modify, and search.
initlist (
length(l): Find the length of the table. Returns the length of the linear table l, that is, the number of data elements in l;
locateelem(l,e): Find operations by value. Find an element with a given keyword value in Table L;
Getelem(l,i): Bitwise search operation. Insert the specified element E in position ith in Table L;
listinsert(&l,i,e): inserts the operation. Insert the specified element E in position ith in Table L;
listdelete(&l,i,e): deletes the operation. Delete the element in the ith position in table l, and return the value of the deleted element with e;
printlist(l): Output operation. Output all element values of linear table l in front and back order;
empty(l): nall operation. If l is an empty table, true is returned, otherwise false is returned.
destroylist (
Note: The implementation of the basic operation depends on the storage structure used for the excite. where "&" denotes a reference in C++.
I would like to introduce you to Yan Weimin's textbook "Data Structure" (C language version), which is currently a classic textbook with a good reputation in China. >>>More
A hash table (also known as a hash table) is a data structure that is directly accessed based on the key value. That is, it accesses records by mapping key values to a location in the table to speed up lookups. This mapping function is called a hash function, and the array that holds the records is called a hash table. >>>More
1. If the left and right subtrees of the node, the left link field lchild indicates its left child node (ltag = 0), otherwise, the left link field indicates its predecessor (ltag = 1). If the node has a right subtree, the right-linked field rchild indicates its right child node (rtag = 0), otherwise, the right-linked field indicates its successor (rtag = 1). >>>More
Just o(n) scans it once, millions of arrays are not big, and c can be opened so big for global variables. >>>More
The algorithm is similar, but the language description is different, C is the basic! However, the C++ language is relatively simple, so it's good to get used to which one!! The data structure is mostly used in C++, it depends on which version of the textbook you use, if you learn C++, then use the C++ version of the textbook, the problem is not very big!! >>>More