"Item 1-basic operations for sequential tables"
Grasp the method proposed in the "0207 Algorithm Change Program" section to turn the algorithm of the sequential table part into a program.
The implementation of the basic arithmetic of the sequential table (corresponding to the implementation of the video 0204 to create the linear table and the implementation of the basic operation of the 0205 sequential table) is tested according to the principle of "minimization". The so-called minimization principle refers to the use of as few basic operations as possible to form a program, and design the main function to complete the test.
As the first practice of this type (each subsequent section has this practice, which is the basis of our learning and the basis for the accumulation of practical results), combined with the relevant algorithms, the proposed process:
(1) The purpose is to test the algorithm of "establishing linear table" createlist, in order to view the results of the table, it is necessary to implement the algorithm displist of "output linear table". In the study displist, it is found that to output linear table and to determine whether the table is empty, it is necessary to realize the algorithm listempty to determine whether the linear table is empty. This, in addition to the main function, is composed of 4 functions. The main function is used to write test-related code.
The structure of the program is as follows:
#include < > //the necessary library files include the #define ... //necessary macro definition //declares a custom function that implements the algorithm, as well as other necessary custom functions //defines the main function for driving tests int mian () {return 0 ;} //define individual custom functions
If on the basis of the above guidance is still difficult to start, please go to the course homepage, find relevant links, observe and then do.
Remember: (1) when not to find a reference, this is to "borrow Power", (2) to find references, did not solve the problem, after observing, throw away the reference, self-completed, this is the fundamental goal. With such a "copy of the Way", copied in the heart, the final results, from your heart, brain and hands.
(2) on the basis of a linear table, it is possible to find the listlength of the linear table length, the getelem of a data element in the specified position in the linear table L, and the algorithm for finding the Locateelem of the element. Added on the basis of the original procedure:
Increase the length of the linear table listlength function and test;
Add a function to Getelem a data element in the specified position in the linear table l and test it;
Add function to find element locateelem and test;
(3) The remaining 4 basic operations: inserting the data element Listinsert, deleting the data element Listdelete, initializing the linear table initlist, destroying the linear table destroylist all can be done with the law, please arrange your own practice route.
When you're done, post your blog post to showcase your practical results.
[Reference Solution]
"Project 2-building" sequential table "algorithm Library"
Understand the "0207 will be algorithmic Change program" section of the proposed method to build their own professional infrastructure algorithm library. This week, the algorithm library for sequential tables was built.
The algorithm library consists of two files:
Header file: List.h, which contains the code defining the sequential table data structure, the macro definition, the declaration of the function to implement the algorithm;
? source file: List.cpp, which contains definitions of functions that implement various algorithms
Please use the multi-file organization of the program, on the basis of Project 1, establish the above two files, and then set up a source file, the main function, to complete the relevant testing work.
When you're done, post your blog post to showcase your practical results.
[Reference Solution]
"Project 3-Find set Merge Set"
Suppose that two sets a and B are represented by two linear table LA and LB, that is, the data element in the linear table is a member of the collection. Design algorithm, using function unionlist (list LA, list LB, List &LC) function to implement the algorithm, to find a new set of C=a∪b, will be two sets of the set in a linear table LC.
Tips:
(1) In addition to implementing the Unnionlist function, you also need to design the code in the main function, call unionlist for testing and demonstration;
(2) can make full use of the built-in front of the algorithm library, the program head directly add #include<list.h> (the most common method of the project, recommended adoption);
(3) It is also possible to implement a function corresponding to the basic operation of the linear table required in the algorithm, in the same file as all the programs designed by them.
When you're done, post your blog post to showcase your practical results.
[Reference Solution]
"Item 4-Sequential table application"
Defining a linear table with sequential structure storage, the design algorithm completes the following work:
1, the deletion of elements in [x, y] all elements, the algorithm requires the time complexity of O (n), the space Complexity of O (1);
2. Move the odd number to the front of all even numbers, requiring the algorithm to have a time complexity of O (n) and a space complexity of O (1).
Tips:
(1) Make full use of the previously established algorithm library to solve the problem of establishing the sequential table and outputting the linear table;
(2) To ensure the complexity of the requirements, design algorithms and special functions to implement the algorithm;
(3) write a program for each job and publish a blog post to showcase your practical results.
[Reference Solution]
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Data structure Practice project--sequential table