Write the key data structures and algorithms: 0. List 1. Stack 2. Queue 3. Two fork tree data structure and construction 4. Sequence of pre-order traversal of Binary Tree 5. Construct Huffman tree (optimal binary tree) 6. Graph data structure, depth-first traversal and breadth-first traversal 7. Topology sort 8. Direct Insert sort 9. Hill sort 10 . Hill sort 11. Bubble sort 12. Quick sort 13. Directly select Sort 14. heap sort 15. Merge sort 16. box sort and base sort 17. Sequential lookup, binary lookup, index order lookup
//ExamTest.cpp: Defines the entry point of the console application. //#include"stdafx.h"#include"stdlib.h"/************************************************************************//*stack data Structure*//************************************************************************/#defineStackSize 1024//Stack sizetypedefCharDatatype;typedefstruct{DataType data[stacksize]; //Stack Array intTop//Stack Top Index}stack;//Empty StackvoidInitstack (Stack *s) { if(s = =NULL)return; S->top =-1;}//determine if the stack is fullBOOLStatckempty (stack*s) { if(s = =NULL)return false; returnS->top = = stacksize-1;}//into the stackvoidPushstack (stack*S,datatype x) { if(s = =NULL)return; if(Statckempty (s))return; Else { //specifies that the current stack is completed and points to the current dataS->top = S->top +1; S->data[s->top] =x; }}//out of the stackDataType Popstack (stack*s) { if(s = =NULL) {Exit (0); } if(Statckempty (s)) {printf ("Stack is empty. \ n"); Exit (0); } Else { returns->data[s->top--];//first use and then minus }}//get top of stack elementDataType GetTop (stack*s) { if(s = =NULL) {Exit (0); } if(Statckempty (s)) {printf ("Stack empty. \ n"); Exit (0); } Else { returnS->data[s->top]; }}/************************************************************************//*queue data structure (circular queue)*//************************************************************************/#defineQueuesize 1024typedefstruct{DataType data[queuesize]; //Queue Array intFront//Queue Header intRear//Queue Tail}queue; //Initialize QueuevoidInitqueue (queue*q) { if(q = =NULL)return; Q->front =0; Q->rear =0;}//determine if the stack is emptyBOOLQueueempty (queue*q) { if(q = =NULL)return false; Else returnQ->front = = q->Rear;}//determine if the queue is fullBOOLQueuefull (queue*q) { if(q = =NULL)return false; return(Q->rear +1)% Queuesize = = q->Front;}//into the queuevoidInsertqueue (queue*Q,datatype x) { if(q = =NULL)return; if(Queuefull (q)) {printf ("Queue Full!\n"); } Else { //The end of the team is added, the tail points to the back one emptyQ->data[q->rear] =x; Q->rear = (Q->rear +1) %queuesize; }}//out QueueDataType Delqueue (queue*q) {DataType x; if(Queueempty (q)) {printf ("Queue is Empty \ n"); Exit (0); } Else{x= q->data[q->Front]; Q->front = (Q->front +1) %queuesize; returnx; }}//take the team head elementDataType Getfrontdata (queue*q) { if(Queueempty (q)) {printf ("queue is empty!\n"); Exit (0); } Else { returnQ->data[q->Front]; }}//take the tail element of the teamDataType Getreardata (queue*q) { if(Queueempty (q)) {printf ("queue is empty!"); Exit (0); } Else { returnQ->data[q->Rear]; }}int_tmain (intARGC, _tchar*argv[]) { return 0;}
View Code
Against the next week self-taught data structure practice subjects