Java Project--Data structure Experiment report

Source: Internet
Author: User

Java Project--Data Structure Summary report

20135315 Song Ning

Experimental requirements

1, the Java language implementation of the data structure in the linear table, hash table, tree, graph, queue, stack, sorting find the algorithm class.

2, the design of the set framework, the use of generic types of implementation.

3, the API writing, and export.

4, using TDD mode, test the program, using Testsuite to integrate the test classes together.

5, with the team members to achieve the integration of code.

Experimental design process

    1. First, self-study the contents of the collection framework chapters, preliminary design related classes.
    2. According to the chapter classification of the textbook of data structure, experiment each data structure class.
    3. In the course of writing the class, I am prepared to use the new functionality of generics after the teacher's guidance.
    4. The data structure classes are abstracted upward, and the abstract functions and interfaces are designed. For example, the linear table includes the linked list and the sequential table, although the two tables are different data structures, but there are many similarities, such as whether the table is empty, delete, insert and other operations are common, so can be extracted, as a linear table interface.
    5. Put different data structures in different packages so that they can be used.
    6. As you write your code, take care to follow up on the help documentation and TDD tests.

Experimental content

1, the writing of linear table

First, according to the nature of the linear table, the function is extracted, the list interface is designed, the sequential table class and the linked list class to implement its function, including IsEmpty () is empty function, insert () Insert function, append () tail interpolation function, search () lookup function, Remove () Delete function, get () get Element function, set () Reset function, Length () function, etc.

Then, in order to implement the above function in the table, in the implementation of the interface, the addition of special functions, such as the constructor function.

Implement the above class in the linked list, notice that in the design of the linked list class, the list node class should be designed so that it can be called in the constructor of the list. There is no specific method in the list node class, there are only 3 different constructor methods.

2. Writing of queue stacks

First, according to the nature of the queue, the function is extracted, the queue interface is designed, including whether IsEmpty () is an empty function, enqueue () enqueued function, dequeue () out of the team function.

Then the sequential queue is implemented by array type, and the list queue is implemented by the linked list type.

First, according to the nature of the stack, the function of the extraction, the design of the stack interface, including IsEmpty () is empty function, push () into the Stack function, pop () out of the stack function, get () get function and so on.

Then the sequential stack is implemented sequentially using the array type, and the linked list is implemented with the linked list type.

3, the diagram of the writing

First, according to the nature of the graph, the function extraction, design graph interface, including static constant maximum weight value 99999,vertexcount () compute vertex number function, get () get vertex element function, Getweight () Get edge weight function, Insertvertex () Inserts a vertex element function, Insertedge () inserts the Edge function, Removevertex () removes the vertex function, Removeedge () removes the Edge function, Getnextneighbor () Gets the adjacency point function, Dfstraverse () Depth traversal function, bfstraverse () breadth traversal function.

Define the edge class to implement the comparable interface, write the construction method, initialize the starting vertex number, end the vertex number and weight, copy the ToString () function, print the parameters of the output edge, implement the CompareTo () function, and compare the starting vertex value.

Write abstract graph Class implementation graph interface, replication dfstraverse () depth traversal function, bfstraverse () Breadth traversal function, add Minspantree_prim () to generate the minimum spanning tree function, The Dijkstra algorithm takes the single-source Shortest path function shortestpath () of Vertex vi in the weighted graph, and the Floyd algorithm takes the shortest path function shortestpath () between each pair of vertices in the weighted graph.

Finally, we write the adjacency matrix class to inherit the abstract graph class, write the constructor, initialize the graph data, and separate the functions in the abstract graph class.

4, the compilation of trees

First, according to the nature of the tree, the function of the extraction, design Bintree interface, specifically including IsEmpty () determine whether the number is an empty function, count () calculate the number of binary tree node function, height () to calculate the binary tree height function, preorder () sequence traversal function, Inorder () Middle sequence traversal function, Postorder () post-order traversal function, Levelorder () sequence traversal function, search () lookup function, GetParent () Get parent node function, Insertroot () Insert root node function, Insertchild () Inserts a child node function, removechild () Removes the child node function, and RemoveAll () deletes all the element functions.

Write the node class, design three kinds of construction methods, for incoming null parameter, the value of incoming node data field, the value of incoming node data field and the left and right subtree.

Write the binary tree class to implement the Bintree interface, implement the method in the Bintree interface, add the following methods: Create () Creates a new node function, GetParent () Gets the parent node function in a two-fork tree starting from a node, preorder () From a section at the beginning of the sequence traversal function, inorder () from a node from the middle sequence traversal function, Postorder () from a node after the post-order traversal function, Levelorder () from a node from a sequence of traversal function, Serach () from a node inserted node function, COUNT ( ) Calculates a binary tree node number function from a node, and height () calculates the binary tree height function from a node.

The binary sorting class is written to inherit the binary tree class, the insert () insertion element method is added, remove () Removes the element method, and remove () removes the node method.

5. Writing a hash table

Write a hash table class. Including two construction methods, null parameter method and incoming table capacity value method, and hash () to find the element hash address function, insert () Insert method, remove () Remove method, search () lookup method, toString () Output hash list information function.

6, the preparation of the API

Add a document comment before each class, declaring the purpose of the class, the methods included, and the author and version information. Note that the writing of the Help document is done as the code is written, which reduces unnecessary hassles. When you have finished writing all the Help documents, select the project to generate the Help document by selecting Javadoc-> from the Java folder by flie->export->, select Generate address, click Finish.

7, the writing of TDD

Because the methods in the class to be tested are associative, I'm testing multiple functions at the same time by designing different scenarios, rather than testing each function in turn. Secondly, the generic method is used in the class to be tested, so the test of the integer type and the string type are designed separately. Finally, using the Testsuite function, the test classes corresponding to all classes are integrated into a test class to manage and test the test class uniformly.

8, the GUI interface writing

Through the self-Learning graphical user interface section, various methods of data structure classes are implemented through the graphical user interface. The implementation of various functions through the button to achieve, which is more important, the interface design. My design is, through a text field output to manipulate the data, the different methods corresponding to the corresponding buttons, through the Operation button to achieve the corresponding function. Sets a text box to output the result of the operation. Because of the time is limited, so the design is relatively rough.

Experimental results and tests

1, complete datastructure project, binsorttreestructure bag, hashtablestructure bag, linkedstructure bag, mapstructure bag, queuestructures bag , the sort package and the Stackstructures package are composed of two-fork sort, hash-list class, Linear table class, graph class, Queue class, sort class, and stack class, note that the method of finding is not uniformly encapsulated, but separately packed in the concrete class package of the United States data structure, Because the lookup method is a basic operation, it is already included in the underlying class and does not have to be encapsulated.

2, the completion of the entire project TDD test.

(1) TDD test results are more comprehensive, specific to each of the classes in each method. Note that there is no private method, because in the program I write, private methods are used for public methods, private methods are called during the implementation of the public method, and if the TDD test passes, the correctness of the corresponding private method is indirectly explained.

(2) In addition, in the process of writing TDD test, I design each kind of data structure of the scene, not the method in the class separated from the test, but one method of testing followed by another method, because the method and the method is connected. (3) It is worth mentioning that, in writing the product code, I used the new structure of generics, and in the course of testing, I used generics for both the integer object and the string object, and tested the results.

3, the various data structure classes are implemented by GUI interface. Through the knowledge of self-taught graphical user interface, before programming, we should design the necessary interface, implement a frame, including the various functions of the button, the Input data text box and the text box to display the result.

4, the preparation of the API. As a result of learning Java video, I developed the habit of writing comments on the side of writing code, after the code has been written, the corresponding comments are also written, so directly under the File tab, select Export is OK.

5. Eventually package all the code and API documents into jar packages for teammates to use.

Experimental summary

1, TDD must be written along with the code. In this experiment, I was finished all the code writing work, only began to write TDD, in the test process, often because of a problem has been unsuccessful, wasting a lot of time to look back for reasons, and add the code has passed a period of time, a lot of code part also some forgotten, and have to start from scratch, Delayed a lot of time, remember that there is a creation of a two-fork sort number of the writing function, because a place greater than as less than, resulting in the program has been a problem, after I read a lot of code, before finally found the problem. Side write program side test, this is my biggest harvest in this experiment.

2, in the design of the class, must learn to extract and abstract, can summarize into the interface and function of abstract functions, we must summarize, at the beginning, I wrote linear table, at that time, the kept of the life of the table, leading to the list and the sequence of many of the functions are similar, but did not extract out, There are too many miscellaneous functions in a class, it is inconvenient to read, not easy to find, by reading reference books, I learned how to extract functions, establish interfaces and abstract classes, and parent classes in the process of learning others ' code.

3, in particular, in the sort sorting class for TDD testing, because the character of the type of the string is ignored, sort java10, java06, java006, because I assume that the results should be java06, java006, JAVA10, Results in a successful test, and after discovering the difference between the string type data and the shaping data, the expected results were modified before the test was passed. However, most of the time, the test does not pass or due to the reason of the program, for example, in the process of creating a two-fork sort number, the order of the built two-fork sorting tree, the output is always a part of the error, and sometimes normal passage, and later found in an if judgment statement, greater than less than the write inverse. The TDD test does identify the problem and makes the program more accurate and complete.

4, API writing in the process of programming is also particularly important. Only the side of the programming side to write comments, in order to reduce the trouble later, many programs after a period of time to see, will find that reading does not understand, this time reflects the importance of annotations. In addition, develop good programming habits, we will gradually grow into a qualified programmer. API writing, not only the programmer's tips, but also to be prompted about the user, so when writing a note, be sure to indicate function functions, the meaning of parameters and the meaning of the return value. Pay more attention to the writing of document annotations, which are explanations of the entire class, so describe the purpose and functionality of the class, as well as the author and version information.

5, through the library to borrow related books, I through only to see part of the content, such as about the list part, through comparison, the final selection of the most suitable for the book, and the book as a reference to achieve future programming. This has enabled me to improve my ability to access information. In this experiment, I think my biggest gain is to learn how to self-study and how to check the information, by borrowing different related books to compare, can be very clear to find the differences in various books, can also find the most suitable for their own level of the book to read the study.

6, in this experiment in addition to the completion of the project code, I also learned something. For example, the development of a project TDD test must follow the code to complete, only in order to ensure that your code can use a variety of different situations, as well as in the process of writing, timely follow-up comments written. How to check the information. How to learn quickly. In this experiment, I found that purposeful learning, more efficient than the blind study of textbooks, but also to ensure that you really learned the knowledge, which is suitable for any subject, any thing of learning.

Java Project--Data structure Experiment report

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.