Some time ago, I learned some basic things, such as Common commands. Now we are going to start learning programming in Linux. Pay attention to the basics and learn the data structure first. The reference material is "Data Structure in Embedded System Software Design". This is one of the basics of embedded system software design. I personally think it is good. Combined with the data structure examples used in UCOS. It also has the implementation of C language, not pseudocode.
At the beginning, we learned a linear table, which consists of a sequence table and a linked list. The sequence table is represented by an array. Designed operations include deletion and insertion. The following code is an overall operation on the sequence table, including creating a table, deleting an element, and inserting an element. The code is successfully debugged in Linux.
Operations on a data sequence table:
# Include <stdio. h> # include <stdlib. h> # define maxsize 100 typedef struct {int data [maxsize]; // store the int last element of the array; // subscript of the last element of the array} squeuelist; int main (void) {int choice, mount, I, dat, Pos; squeuelist * l; while (1) {printf ("linear sequence table operation exercise \ n"); printf ("1. create an ordered table \ n "); printf (" 2. insert data \ n "); printf (" 3. delete data \ n "); printf (" 4. print sequence table \ n "); printf (" 5. exit \ n "); printf (" Enter your choice (1-5): "); scanf (" % d ", & choice); Switch (choice) {Case 1: printf ("Enter the name you want to create Number of created elements: "); scanf (" % d ", & mount); If (Mount> maxsize) {printf (" the number of created elements exceeds the specified range! "); Break;} printf (" Enter data: "); for (I = 0; I <Mount; I ++) {scanf (" % d ", & L-> data [I]);} l-> last = Mount-1; break; // insert operation Case 2: printf ("Enter the value and position of the element to be inserted (Position 1 indicates element 0, and so on):"); scanf ("% d", & dat, & Pos); If (L-> last> MAXSIZE-1) {printf ("Space overflow! \ N "); break;} else if (Pos <1 | POS> L-> last + 2) {printf (" the inserted position is invalid! \ N "); break ;}else {for (I = L-> last; I >=pos-1; I --) {L-> data [I + 1] = L-> data [I];} l-> data [pos-1] = dat; L-> last + = 1 ;} break; // Delete Case 3: printf ("Enter the location where you want to delete the element (Position 1 indicates the element 0, and so on ):"); scanf ("% d", & Pos); If (Pos <1 | POS> L-> last + 1) {printf ("the input position is invalid! \ N "); break;} else {for (I = Pos; I <= L-> last; I ++) {L-> data [I-1] = L-> data [I];} l-> last-= 1;} break; // print the output sequence table case 4: printf ("sequence table:"); for (I = 0; I <= L-> last; I ++) {printf ("% d ", l-> data [I]);} printf ("\ n"); printf ("Number of sequential tables: % d \ n ", l-> last + 1); break; // exit program case 5: exit (0); break; default: break;} return 1 ;}
Characteristics of the sequence table:
- It is inconvenient to insert or delete a table. data must be moved at the end of the table. The average time complexity is O (n), which is less efficient.
- Because the sequence table occupies the sequence space and you do not know how much space you will use, the sequence table will pre-allocate the space in advance. If the space is large, it will cause a waste. If it is small, it will cause overflow.
- Of course, the advantage is that the search is convenient. You only need to use the array element subscript to find the desired element.
Because we are new to VIM, we are not very familiar with vim. However, after some transformation of the configuration file, I feel that Vim is still very good and I like it a bit.