In-class experiment of data structure in Wuhan University of Technology


Preface

The general content to be recorded in this article:
I share my thoughts on the in-class experiment of the data structure course I learned in the first semester of the sophomore year and provide it for your reference.

Main equipment and consumables

1. One PC with Windows 10 operating system installed
2. The Microsoft Visual Studio 2019 development environment is installed on the PC system


The following is the content of this article, the following cases are for reference

1. Application of linear table

Experiment description

Project name: Student information management system
Project content: Design a student information management system to add, delete, modify, and query basic student information. Each student information includes student ID, name and grade point. The system is required to complete the following main functions:
(1) Display: display all current student information records;
(2) Input: input a student information record from the keyboard and insert it into the specified position in the table;
(3) Search: according to student ID or record Find the location of student information;
(4) delete: delete the specified position of student information records;
(5) update: updates the specified position of student information records;
(6) statistics: statistics number of secondary students;
(7) Sort by: Sort according to student number or grade point;
(8) Clear: Clear all records in the table.

Data structure design

typedef struct {
    
    //每个学生数据的组成
	char number[8];
	char name[20];
	double score;
}Student;
typedef struct LNode {
    
    //线性单链表的存储结构
	Student data;
	struct LNode* next;
}LNode, *LinkList;

Second, the application of the stack

Experiment description

Project name: Simple calculator program
Project content: Write a program to simulate the work of a simple arithmetic unit: input a calculation formula (without spaces), meet the equal sign "=" to indicate the end of the input and output the result. Assuming that the calculator can only calculate addition, subtraction, multiplication and division operations, the operands and results are both integers. The following functions are required: Input the infix expression from the keyboard and calculate the value of the infix expression.

Data structure design

typedef struct//操作数栈
{
    
    
	int* top;
	int* base;
	int listsize;
}List;
typedef struct//操作符栈
{
    
    
	char* top;
	char* base;
	int nodesize;
}Node;

Three, the application of the tree

Experiment description

Recursively implement the following algorithms:
1. Represent a binary tree with a binary linked list, and build a binary tree;
2.Output the result of the middle order traversal of the binary tree;
3.Output the preorder traversal result of the binary tree;
4.Output the post-order traversal result of the binary tree;
5.Calculate the depth of the binary tree;
6. Count the number of nodes in the binary tree;
7. Count the number of leaf nodes of the binary tree;
8. Count the number of nodes with degree 1 of the binary tree;
9. Output the path from each leaf node to the root node in the binary tree.

Data structure design

//二叉树的二叉链表存储表示
typedef struct BiNode
{
    
    
	char data;						//结点数据域
	struct BiNode* lchild, * rchild;	//左右孩子指针
}BiTNode, * BiTree;

Fourth, the application of undirected graphs

Experiment description

Project name: Communication network construction
Project content: To establish a communication network between n cities, only n-1 lines are needed to connect n cities. It is required to establish this communication network on the premise of the most economical cost.
(1) Complete the input of city information.
Insert picture description here
(2) Complete the editing of city information, including the increase, deletion, and information modification of cities and the distance between cities.
(3) Allow the user to specify the following two strategies for the construction of the communication network:
1) Use the Prim algorithm to construct the communication network;
2) Use the Kruskal algorithm to construct the communication network;

Data structure design

typedef char VerTexType;              		//假设顶点的数据类型为字符型 
typedef int ArcType;
#define MVNum 100                       	//最大顶点数
#define MaxInt 32767                    	//表示极大值,即∞

//----------------图的邻接矩阵---------------------
typedef struct {
    
    
	VerTexType vexs[MVNum];               //顶点表 
	string name[MVNum];
	ArcType arcs[MVNum][MVNum];      		//邻接矩阵 
	int vexnum, arcnum;                		//图的当前点数和边数 
}AMGraph;
int Vexset[MVNum];							//辅助数组Vexset的定义

//辅助数组Edges的定义
struct {
    
    
	VerTexType Head;						//边的始点
	VerTexType Tail;						//边的终点
	ArcType lowcost;						//边上的权值
}Edge[(MVNum * (MVNum - 1)) / 2];
//辅助数组的定义,用来记录从顶点集U到V-U的权值最小的边
struct {
    
    
	VerTexType adjvex;						//最小边在U中的那个顶点
	ArcType lowcost;						//最小边上的权值
}closedge[MVNum];

Five, the application of directed graph

Experiment description

Project name: Teaching plan preparation system
Project content: Each major of the university must develop a teaching plan. Assuming that any major has a fixed length of study, each academic year contains two semesters, and the length of each semester and the upper limit of credits are equal. The courses offered by each major are determined, and the arrangement of the courses must meet the prerequisite relationship. The prerequisite courses for each course are determined, there can be as many as you want, or there can be none. Each course occupies exactly one semester. Try to design a teaching plan preparation system under this premise. The system needs to meet the following functions:
(1) Complete the reading of the information of the course further study catalogue;
Insert picture description here
(2) Complete the editing of the course further study catalog information, including adding and deleting courses, Information modification, etc.;
(3) The semester of the student's teaching plan is 6, and the credit limit for each semester is 10 points. The user is allowed to specify the following layout strategies for the output of the teaching plan.
1) Make the burden of students in each semester as even
as possible ; 2) Make the courses as concentrated as possible in the first few semesters.
If there is no solution to the problem according to the given conditions, report the appropriate information; otherwise, output the teaching plan to the file specified by the user, and design the plan format by yourself.

Data structure design

typedef struct arcnode
{
    
    
	 int adjvex;
	 arcnode* next;
}arcnode;

typedef struct 
 {
    
    
	 char name[20];
	 string classsid;
	 int credit;
	 int indegree;
	 int state;
	 arcnode* first;
 }vnode,adjlist[100];
 
 typedef int Elemtype;
 
 typedef struct 
 {
    
    
	 adjlist vertices;
	 int  vexnum, arcnum;
 }algraph;
 
 typedef struct
 {
    
    
	 Elemtype* base;
	 Elemtype* top;
	 int stacksize;
 }sqstack;

Six, search and sort

Experiment description

On the basis of the student management system designed in Experiment 1, the following functions are added:
(1) Use direct insertion sort or half insertion sort to sort by name;
(2) Use quick sort to sort by student number;
(3) Half-by name Finding requires the use of a recursive algorithm to successfully return the student's student ID and grade;
(4) According to the student ID, the search is performed by half and a non-recursive algorithm is required to successfully return the student's name and grade.

Data structure design

typedef struct
{
    
    
	string name;
	string number;
	int score;
}ElemType;
//顺序表的存储结构                         
typedef struct
{
    
    
	ElemType* r;	         						//存储空间的基地址
	int  length;            						//顺序表长度
}SqList;											//顺序表类型



Seven, Huffman coding

Experiment description

Realize a Huffman encoding system, the system includes the following functions:
(1) Character information statistics: read the source file SourceFile.txt to be encoded, and count the characters and their frequency.
(2) Build a Huffman tree: Build a Huffman tree based on the statistical results.
(3) Establish the Huffman code table: use the obtained Huffman tree to save the code table corresponding to each character in the file Code.txt.

Data structure design

typedef struct
{
    
    
	int weight;
	int parent, lchild, rchild;
}HTNode, * HuffmanTree;
typedef char** HuffmanCode;


to sum up

Because of the large amount of experiment content, not all the source code is shown here. For details, please refer to the following experiment report.
Link: Chong Chong Chong ~
Extraction code: mjlh
copy this content and open the Baidu Netdisk mobile phone App, the operation is more convenient

Guess you like

Origin blog.csdn.net/mo_zhe/article/details/112733427