brief introductionFunction: store dataVersion: 5.7 and 8.0The three-tier structure of MySQLSQL statement classificationDDL: Data definition (create)DML: data operation (add insert, delete and modify)DQL: Data Query (select)DCL: data control (management database: user permissions, grand, revoke)Open MySQL for database operation1mysql -u root -pshow database1SHOW DATABASES;Create Database1CREATE DATABASE database nameUse Database1USE database name;'' can avoid keywords. To name the database with keywords, you can use ''Backup databaseRun in shellThe backup file is a series of sql statements entered by the user1234//Backup database mysqldump - u username - p - B database 1 database 2 database n>file.sql/backup table mysqldump - u username - p database 1 table 1 table 2>file.sqlRestore DatabaseStatements do not use semicolons1Source backup folder pathDelete Database1DROP DATABASE database name;data typetypeintchar...
Basic structure of inline assembly 1234asm asm qualifiers (AssemblerTemplate: OutputOperands [: InputOperands [: Clobbers]])AssemblerTemplate Assembler Template OutputOperands Output Operands InputOperands Input Operands ClobbersSample code1234567int src = 1;int dst; asm ("mov %1, %0\n\t" "add $1, %0" : "=r" (dst) : "r" (src));printf("%d\n", dst);This code copies src to dst and adds 1 to dst.Multiple assembler instructions can be placed in one asm string, separated by characters commonly used in system assembly code.The combination that is valid in most places is the newline character
1234567891011121314151617181920212223242526272829303132333435void dijkstra(int graph[][6],int len,int start){ int isshort[len];/*Record whether the shortest path is found */int dis [len]; int path[len];/*recode pre node*/ for(int i=0;i<len;i++){ dis[i]=graph[start][i]; if(graph[start][i]!=INF) path[i]=start; else path[i]=-1; isshort[i]=0; } isshort[start]=1; for(int i=0;i<len;i++){ int min=INF; int minindex=-1; for(int j=0;j<len;j++){ if(isshort[j]!=1&&dis[j]<min){ ...
Virtual address space of programBefore understanding the stack frame of a function, let's first understand the concept of virtual address space.The operating system allocates a virtual address space to each c program instance, creating the illusion that each program has exclusive memory.The memory addresses are distributed as follows.The stack area stack is a data structure that is first in and then out.In the address space of C program, the% esp register points to the top of the stack, and the% ebp register points to the bottom of the stack.The stack extends from the high address to the low address. When entering the stack, the esp moves to the low address. When exiting the stack, the esp moves to the high addressFunction calls depend on the stack.Call the function, and the stack increases.The function returns, and the stack shrinks.Function call 1The process of calling a function is essentially to modify the value of PC (program counter), which points to the address of the next instruction to be executedBefore calling the functionThe parameters are stacked from right to left,The call instruction puts the return address on the stack, which indicates the next execution statement when the function returnsParameter transfer is carried out on the stack in a 32-bit system.In the X86-64 architecture, function parameters are stored in registers, respectively in di, si, dx, cx, r8, and r9 registers.If the parameter of the function is greater than 6, the excess part needs to be passed using the stackLocal variable 12345678long caller(){long argl = 534; long arg2 = 1057 ...
Implementation ideasArrange the edges in the graph from small to largeTraverse the array of edgesIf the two vertices of the edge do not exist in the same set, the set where the two points are located will be merged, and the two points will be connectedOtherwise skipSimulation processSort by edge from small to large to build auxiliary arrayTo implement the Kruskal algorithm, an auxiliary array is required. The data element structure is as follows12345typedef struct Edge{ int head; int tail; int weight;}Edge;The Edges array needs to be sorted according to the length of the edge weight from small to large. The sorting algorithm is as follows123456789101112131415161718/* Quick sort */void Sort (struct Edge edges [], int l, int r) {if (l>=r) return;int i=l-1; int j=r+1; int mid=edges[(l+r)/2].weight; while(i<j){ while(edges[++i].weight<mid); while(edges[-- ...
Data structure of concurrent query and concurrent query1int S[MAXSIZE];The collection where the query element is located1234567int Find(int sets[],int x){ int index=x; while(sets[index]!=-1){ index=sets[index]; } return index;}Merge two sets1234void Union(int sets[],int root1,int root2){ if(root1==root2) return; sets[root2]=root1;}And check the set and optimize the union optimization 123456789101112131415161718/* Combine the sets of the two root nodes into a set */void UnionSets (int sets [], int root1, int root2) {if (root1==root2) return; if (sets [root1]>=sets [root2]) {s
Algorithm Introduction Prim algorithm is a graph algorithm used to build the minimum spanning tree.The vertices of the minimum spanning tree are all connected, that is, starting from any vertex, you can reach all the vertices of the graph, and the weight of all its edges is the smallest.Algorithm description:From the minimum spanning tree set, select the vertices with the smallest edge weight value and not in the spanning tree set to add to the minimum spanning tree set, and repeat the above operation until all points are added to the minimum spanning tree set.To realize the algorithm, five villages (numbered 0-4) need to build roads in each village, so that all villages can be connected at the lowest cost.Here we use the adjacency matrix to represent the above figureTwo auxiliary arrays, lowcost and edge, are needed to implement the Prim algorithm.The lowcost array is used to store the distance from the minimum spanning tree set to each vertex. The array index is associated with the vertex.For example, owcost [3] indicates the distance from the minimum spanning tree set to vertex 4If the element value in the array is 0, it means that the vertex exists in the minimum spanning tree set; otherwise, it means the weight size.Edge is used to store the edge relationship of vertices. Edge [1]=2 indicates that it is connected with Node 1 and Node 2.12int lowcost[graph->vexnum];int edge[graph->vexnum];Execution process:Select a node to add to the minimum spanning tree collection, and initialize the lowcost and edge arraysRepeat steps 3 below
Adjacency matrix representation of graph Data structure definition 123456789typedef struct AdjNode {struct AdjNode * next;/* subsequent vertex */char vtxname;/* vertex name */} AdjNode;typedef struct Graph{ struct AdjNode* list[MAX_SIZE]; /*Header node list */int vtxnum;/* vertex number */} Graph;Figure Operation 12345678910111213141516171819202122232425/* Initialization Diagram */struct Graph * initGraph()/*Find the vertex index according to the vertex name */int findNodeIndex (Graph * graph, char vtxname);/* Find the vertex pointer according to the vertex name */AdjNode * findNode (Graph * graph, char vtxname);/* Auxiliary function for deleting elements in the adjacent edge chain list */int deleteEdgeHelp (AdjNode * head, char vtx);/
A graph is a one to many data type.The graph representation methods include adjacency matrix method and cross linked list method.The operations of the figure includeAdjacent (G, x, y): judge whether there are edges<x, y>or (x, y) in graph G.Neighbors (G, x): List the edges adjacent to node x in graph G.InsertVertex (G, x): insert vertex x in graph G.DeleteVertex (G, x): deletes vertex x from graph G.AddEdge (G, x, y): If the undirected edge (x, y) or the directed edge<x, y>does not exist, add the edge to the graph G.RemoveEdge (6, x, y): If an undirected edge (x, y) or a directed edge<x, y>exists, the edge is deleted from the graph G.FirstNeighbor (G, x): Find the first adjacent point of vertex x in graph G. If there is one, return the vertex number.If x has no adjacent points or x does not exist in the graph, then - 1 is returned.Adjacency matrix representation is suitable for dense graphsGraph storage mode 1234567 # define MAX_SIZE 10typedef struct Graph {int vexnum;/* Number of nodes */int vertices [MAX_SIZE]/*Node array */