|
Postgraduate examination questions in a school
(1) The subroutine sort () directly selects and sorts the linked list. The linked list that implements sorting does not have flag nodes, and the first pointer is provided by parameters. To facilitate sorting, this function adds an auxiliary header flag node to the linked list before sorting, and then deletes this node after sorting is complete.
typedef struct node
{
int value;
struct node * next;
} node;
void sort (_______ (1) _______ h)
{
struct node * p, * q, * r, * s, * h1;
h1 = p = (node *) malloc (sizeof (node));
p-> next = * h;
while (p-> next)
{
q = p-> next;
r = p;
while (q-> next)
{
if (q-> next-> value <_______ (2) _______)
r = q;
q = q-> next;
}
if (r! = q)
{
s = _______ (3) _______;
_______ (4) _______ = s-> next;
s-> next = _______ (5) _______;
}
p = p-> next;
}
* h = _______ (7) _______;
free (h1);
}
(two)
The following program inputs the order and "lucky number" of a square matrix to generate a nebula square matrix. The lucky square is like this: cross out any row and any column of it, write down the value of the intersection; then arbitrarily cut out a line and column in the rest of the square, and write down the value of the intersection; When there are no values left in the square matrix, the sum of all the values recorded is exactly the lucky number specified in advance.
The rand () function in the program: returns a random positive integer.
#define N 30
#include <stdio.h>
#include <math.h>
void main ()
{
int lucky [N] [N], row [N], col [N];
int n, lucky_n, k, sum = 0, i, j;
printf ("Please enter the number of squares"); scanf ("% d",&n);
printf ("Please enter a lucky number"); scanf ("% d",&lucky_n);
k = lucky_n / n;
if (k == 0) printf ("The input value is too small");
for (i = 0; i <n; i ++)
{
row [i] = rand ()% k;
col [i] = rand ()% k;
sum + = _______ (1) _______;
}
col [n-1] + = _______ (2) _______;
for (i = 0; i <n; i ++)
for (j = 0; j <n; j ++)
_______ (3) _______;
for (i = 0; i <n; i ++)
{
for (j = 0; j <n; j ++)
printf ("% d", _______ (4) _______);
}
} |
|