On the sixth day (I remembered the "last lesson" ^ _ ^) 10/7/2003
After the test, the teacher did not say much, he just gave us near the three-year questions and tells the two topics in detail: a recursive, another trace. But today I don't know what is going on, I feel particularly tired, I also want to sleep. So there is no feeling. I don't say it here, the two topics have, the recursion is the last question in 2001, the back is in the "programmer tutorial" P416, the teacher said that the elevation once has been examined, interested ourselves can see it. . The teacher deliberately got an afternoon test, I now take him out to let you refer to the reference. When you come here, you will come here!
Programmer test afternoon test (simulation)
First, insert a string into a location of another string (the number of elements)
Char * Insert (Char * S, Char * T, INT POSITION)
{INT i;
Char * target;
IF (Position> Strlen (T)) Printf ("Error");
Else
{For (i = 0; i <(1); i )
{IF (i Target [i] = s [i]; Else {IF (i <(2)) Target [i] = t [i]; Else (3); } } } Return Garget; } Second, the number of two positive integers in the ruster INT F (int A, int b) {IF (a == b) (4); Else {IF (a> b) Return F (A-B, B); Else (5); } } Third, ask for average of all elements of a linked list Typedef struct {int Num Float ave; } Typedef struct node {float data; Struct Node * Next; } Node; Back * aveage (node * hEAD) {Back * p, * q; P = (back *) malloc (sizeof (back)); IF (head == null) {P-> Num = 0; P-> AVE = 0;} Else {(6); P-> Num = Q-> Num 1; (7); Retuen P; } Main () {Node * h; back * p; H = crete (); / * Establish a linked list of H-headed pointers * / IF (h == null) Printf ("no element"); Else {P = aveage (h); Printf ("The mean of the chain element is: 6F", P-> AVE); } } Four, Hill sort It is known to be sorted sequence data [n]; Hill's sorted increment sequence is d [m], where D [] sequence is sorted, and D [m-1] = 1. The method is to sort the sequence, in the first sequence, divide the entire sequence into a D [i] subsequence in the quantity D [i], and sort each subsequence is sorted by direct insertion sorting method. Hill sorted program: Void shellsort (int * data, int * D, int N, int m) {INT I, J; For (i = 0; i For (j = 0; (1); J ) Shell ((2)); } Void shell (int * data, int d, int num, int N) {INT I, J, K, TEMP; For (i = 1; (3); i ) {J = 0; Temp = Data [J i * D]; While ((j
J ; For (k = j; k
Data [k 1] = data [k]; (5); (6)} } Five, seeking the width of the tree The so-called width refers to the total number of nodes on the layer of the number of nodes in each layer of the binary tree. This algorithm is traversed by the binary tree, using a queue Q, let the root node into the queue, finally out of the queue, if there is a left and right tree, the left and right subsacking nodes are inciting the queue, so repeated, until the queue is empty. Int width (bintree * t) {INT front = -1, rear = -1; / * Queue initialization * / INT FLAG = 0, count = 0, p; / * P is used to point to the maximum number of nodes in the FLAG recording layer to the rightmost nodes of the layers of the tree. * / IF (t! = null) {REAR ; (1); flag = 1; p = Rear; } While ((2)) {Front ; T = q [Front]; IF (t-> lchild! = NULL) {REAR ; (3); count ;} // IF (t-> rchild! = null) {REAR ; Q [REAR] = T-> rCHILD; (4); IF (front == p) / * The current layer has been traversed * / {IF ((5)) Flag = count; count = 0; // P = REAR; / * P pointing to the next layer of the rightmost node * /} } Return (Flag); } Six, interval coverage It is located on the real-axis (X0, X1, ..., XN-2, XN-1), and now requires the N points to be covered with a unit closed section of length 1, and how many unit closed intervals are required . Int cover (float x [], int Num) {FLOAT START [NUM], END [NUM]; INT I, J, FLAG, count = 0; For (i = 0; i {FLAG = 1; For (j = 0; j <(1); J ) {IF ((START [J]> X [I]) && (End [J] -x [I] <= 1)) (2); ELSE IF ((3)) end [j] = x [i]; Else IF (x [i]> start [j]) && (x [i] IF (Flag) Break; } IF ((4)) {End [count] = x [i]; (5); count ;} } Return count-1; } Start [count] = x [i] Seven, the mix in Go In the Go game, some side (assuming is black) After a certain position (i, j) of the board, it is possible to extract the other party (a series of sub-places). A checkerboard is represented by W [19] [19], if W [I] [j] = 0 is indicated in position (i, j) no sub-, W [i] [j] = 1 indicates that the position is black , W [i] [j] = - 1 indicates that the position is white. The slurry algorithm can be implemented with a backtracking method. The following procedure is a black chess (TAG = 1) to determine if some white bons can be eaten after the (i, j) position, which can be referred to in a linear form. The corresponding data structure of the problem is: #define length 19 / * Chessboard size * / #define max_num 361 / * The number of points in the board * / Struct Position {Int row; int }; / * Chess position * / Struct killed {struct position data [max_num]; int Num } * P; / * Store can eat chess position * / Struct stack {struct position node [max_num]; int top; }; / * Stack * / INT W [Length] [Length]; / * Both sides of the board * / INT Visited [Length]; / * gives the selected chess pieces, the initial value is 0, searches for 1 * / struct killed * kill (int W [length], INT R, INT C, int Tag) {Struct killed * p; Struct Position * S; Struct stack s; For (i = 0; i For (j = 0; j (1) ; S.TOP = -1; p-> Num = -1; IF (W [R-1] [C] == Tag * (- 1)) S-> row = r-1; S-> COL = C; ELSE IF (W [R 1] [C] == Tag * (- 1)) S-> ROW = R 1; S-> COL = C; ELSE IF (W [R] [C-1] == Tag * (- 1)) S-> row = r; S-> COL = C-1; ELSE IF (W [R] [C 1] == Tag * (- 1)) S-> row = r; S-> COL = C 1; ELSE P-> LEN = 0; RETURN P; Push (s, s); Visited [S-> ROW] [S-> COL] = 1; Flag = Search (S, TAG); While ((2)) {Push (S, S); Visited [S-> ROW] [S-> COL] = 1; (3); } While (S-> TOP> = 0) {POP (s); (4); Flag = Search (S, TAG); While (flag) {Push (s, s); Visit (s); Flag = Search (s); } } } Void Push (Struct Stack * S, Struct Position * S) {S-> TOP ; S-> Node [S-> Top] .row = S-> ROW; S-> Node [S-> TOP] .col = S-> COL; P-> NUM ; P-> Data [P-> Num ].Row = S-> ROW; P-> DATA [P-> Num] .col = S-> COL; } Void Pop (struct stack * s) {S-> TOP -; } Struct Position * gettop (struct stack * s) {Struct position * s; S-> row = s-> data [S-> Top] .ROW; S-> row = s-> data [S-> Top] .ROW; Return S; } Int search (struct position * s, int tag) {Int row, col; Row = S-> Row; COL = S-> COL; IF (W [ROW 1] [col] = (- 1) * TAG) && (! Visited [Row 1] [col]) {S-> ROW = ROW 1; S-> COL = COL; RETURN 1;} IF (w [row-1] [col] = (- 1) * tag) && (! Visited [row-1] [col]) {S-> row = row-1; S-> COL = col; return 1;} IF (w [ROW] [COL 1] = (- 1) * tag) && (! Visited [ROW] [COL 1]) {S-> row = row; S-> COL = COL 1; RETURN 1;} IF (w [ROW] [COL-1] = (- 1) * TAG) && (! Visited [ROW] [COL-1]) {S-> row = row; s-> col = col-1; return 1} (5); } answer: (1) Strlen (S) Strlen (T) (2) Position Strlen (T) (3) Target [i] = s [i-strlen (t)] (4) RETURN A (5) RETURN F (A, B-A) (6) q = aveage (head-> next) (7) P-> ave = (head-> data Q-> AVE * Q-> Num) / P-> Num (1) j (1) q [REAR] = T (2) Front LCHILD (4) Count (5) Flag (1) count (2) (x [i]> end [j]) && (x [i] -start [j] <= 1) (3) start [j] = x [i] (4)! Flag (5) (1) Visited [i] [j] = 0 (2) Flag (3) Flag = Search (S, TAG) (4) s = Gettop (s) (5) Return 0 The class has been fully completed, and it should also be a pen. I hope to inspire everyone! Give me a reason for don't add me, if not, QQ: 8760391 attitude determines everything! Finally, I wish you all a smooth pass. Updated: 10/8/2003 4:27:37 PM