| |

VerySource

 Forgot password?
 Register
Search
View: 3561|Reply: 20

Find a dilemma and it took me an afternoon.

[Copy link]

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-2-18 02:00:01
| Show all posts |Read mode
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) _______);
     }
}
Reply

Use magic Report

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-4-22 21:30:01
| Show all posts
Like yourself
Reply

Use magic Report

1

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-4-23 11:00:01
| Show all posts
(1) Is there a problem with the problem?
Reply

Use magic Report

0

Threads

25

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 France

Post time: 2020-4-23 11:15:01
| Show all posts
Also exam questions,
do it yourself
Reply

Use magic Report

0

Threads

19

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-4-25 09:45:01
| Show all posts
It ’s not difficult, just think clearly
Reply

Use magic Report

0

Threads

10

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-25 20:45:02
| Show all posts
Question 1, I feel like sorting the linked list in a manner similar to the array bubble sort method.

However, the way of expression is a bit difficult to understand.

MARK
Reply

Use magic Report

1

Threads

14

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-27 14:15:01
| Show all posts
Top lz, come on
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-4-28 20:00:01
| Show all posts
Choose sorting, understand the idea

//
// Choose the smallest one from the data and exchange it with the first value,
// Choose the smallest AND from the rest
// The second exchange, and so on.
//
template <typename T>
void SelectSort (T * pData, int Count)
{
    int iTemp = 0;
    int iPos = 0;
    for (int i = 0; i <Count-1; i ++)
    {
        iTemp = pData [i];
        iPos = i;
        for (int j = i + 1; j <Count; j ++)
        {
            if (pData [j] <iTemp)
            {
                iTemp = pData [j];
                iPos = j;
            }
        }
        pData [iPos] = pData [i];
        pData [i] = iTemp;
    }
}
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-5-12 14:30:01
| Show all posts
(2)
#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 square matrix order"); scanf ("% d",&n);
   printf ("Please enter the 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) _______; row (i) + col (i)
    }
    col [n-1] + = _______ (2) _______; lucky_n-sum;
    for (i = 0; i <n; i ++)
       for (j = 0; j <n; j ++)
           _______ (3) _______; lucky [i] [j] = row [i] + col [j]
    for (i = 0; i <n; i ++)
    {
       for (j = 0; j <n; j ++)
           printf ("% d", _______ (4) _______); lucky [i] [j]
     }
}
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-5-14 08:15:01
| Show all posts
Looking forward to the second answer.
Even after doing it, I still can't get the result.
I hope the expert can give me a click.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list