“This is the third day of my participation in the November Gwen Challenge. See details of the event: The last Gwen Challenge 2021”.

main()

{

Int n[5] = {0,0,0}, I,k = 2;

for(i = 0; i < k; i++)  n[i] = n[i] + 1;

printf(“%d\n”,n[k]);

}

 

The answer is zero

You get an infinite loop

Int main()

{int i=0;

  while(i<10)

  {  if(i<1) continue;

//continue skips this loop to execute the next loop;

     if(i==5)break;

     i++;

  }

}

C language modular operations: E%s s divisor E dividend

 

The general form of the for loop is as follows:

For (expression 1; Expression is 2; Expression 3) Body of loop

The for loop executes as follows:

1. Calculate expression 1;

2. Calculate expression 2. If the value is not 0, go to Step 3. If the value is 0, go to Step 5.

3. Execute the for loop body once;

4. Calculate expression 3 and move to Step 2;

5. End the loop.

For loop The condition that causes an infinite loop

for(i=0; i<=10; i++) { ; }

1. Omitting I <=10 causes an infinite loop

2. Omitting i++ causes an infinite loop

3. All three expressions in parentheses () are omitted, causing an infinite loop

About the body of the while “,

1. The conditional expression is always executed once more than the loop body;

2, first judge whether the condition is established, if the condition is established, the cycle body will be executed; otherwise, it will not be executed.

About the body of the do loop while (conditional expression);

1. Execute the loop body first to judge the condition. If the condition is established, execute the loop body; otherwise, it will not be executed.

2. The conditional expression is executed the same number of times as the body of the loop

3. The body of the do-while statement is executed at least once

 

while((ch=getchar())! =’N’) printf(“%c “,ch);

The condition in the loop is that the body of the loop is executed when N is not read, and ends when N is read.

Topic:

Let’s say n numbers are stored in order from largest to smallest in array x, and the following changes the order of n numbers in array X from smallest to largest

Resolution:

If you want to store them in ascending order, you just swap the values of the symmetric positions, where I is n minus I minus 1, and the number of comparisons is n over 2.

Int t =0;

For(int I =0 ; i<n/2 ; i++){

t=X[i];

X[i]=x[n-i-1];

X[n-i-1]=t;

}

// Compute the greatest common divisor of m and n

int main()

{  int m,n;

   scanf(“%d%d”,&m,&n);

while(m! =n)

{ while(m>n){ m=m-n; }

while(n>m){ n=n-m; }

   }

   printf(“%d\n”,m);

}

1. For a linear table of length N, how many times do you need to sort in the worst case and compare in the worst case

Bubble sort requires n/2 front-to-back scans and n/2 back-to-front scans, requiring n(n-1)/2 comparisons

Quicksort also has n(n-1)/2 worst case comparisons.

 

dichotomy

Binary lookups work only for ordered tables with sequential storage.

If you use a chain storage structure, you can only use sequential lookup,

Orderly table

An ordered table is a linear table in which the elements are arranged in non-decreasing order of value (that is, from smallest to largest, but adjacent elements are allowed to have equal values).

 

Logical structure of data

Divided into: linear structure and nonlinear structure

A logical structure of data can be expressed as a variety of storage structures, such as sequence, link, index and other storage structures. The efficiency of data processing is different with different storage structures

 

The data storage structure is

Sequence and chain are data storage structures

 

Linear and nonlinear structures

Definition of linear structure: ① have and only one root node; ② Each node has at most one antecedent and at most one aftercomponent. The data structure is called linear structure, also known as linear table

So linear lists, stacks and queues, and linear linked lists are linear structures, while binary trees are nonlinear structures.

Doubly linked lists and binary tree lists

The nodes of doubly linked lists and binary linked lists have two pointer fields, the former is linear structure, the latter is nonlinear structure.

 

A data structure with only one root and only one leaf must be linear