C array to store names and sort them?

Updated on technology 2024-05-07
6 answers
  1. Anonymous users2024-02-09

    Bubbling sorting, fractions into an array, names into a two-dimensional string, the first dimension of the string corresponds to the subscript of the array, and the sorting is exchanged once, and the exchange can be achieved by a buffered string t, using strcpy (similar to the assignment of variables), for example.

    char s[2][20];

    char t[20];

    s[0] = "abc", s[1] = "abcd";

    strcpy(t, s[0]);

    strcpy(s[0], s[1]);

    strcpy(s[1], t);

    The header file include is required

  2. Anonymous users2024-02-08

    You can use an array of structs.

  3. Anonymous users2024-02-07

    Summary. Hello dear, I'm glad to answer this question for you, Array element sorting in C refers to sorting the elements in the array so that the elements in the array are arranged in a certain order. Commonly used sorting methods are bubble sorting, quick sorting, selection sorting, insertion sorting, etc.

    C language array element sorting.

    Hello dear, I'm glad to answer this question for you, Array element sorting in C refers to sorting the elements in the array so that the elements in the array are arranged in a certain order. Commonly used sorting methods are bubble sorting, quick sorting, selection sorting, insertion sorting, etc. I hope my answer can help you.

    Hello dear dear I am glad to answer this question for you, Array element sorting in C refers to sorting the elements in the array, so that the elements in the array are arranged in a certain order. Commonly used sorting methods are bubble sorting, quick sorting, selection sorting, insertion sorting, etc. I hope my answer can help you.

    Is it the answer you need, if not, please describe it in detail.

  4. Anonymous users2024-02-06

    Use the bubbling sorting method.

    Programming: <>

    Explanation:1The first for loop.

    Loop through the array to enter 4 variables.

    2.Second for loop: This loop means that if a[0]>a[1], the values of the two variables are exchanged, and the loops are used to compare them in turn.

    It should be noted that i<3, because there is i+1 in it, and i is taken to 2 at most, that is, i+1 is correct to be taken at a maximum of 3.

    3.The third for loop: use the loop to output the sorted array in turn, and add a space to each output for easy distinction.

  5. Anonymous users2024-02-05

    There are many sorting algorithms in a data structure:

    Select Sort, Interchange Sort, Bubbling Sort, Hill Sort, Quick Sort, Merge Sort, and so on.

    1.Swap sorting methods.

    The idea of swapping sorting is to first find the smallest number and put it in the first position, and then find the second largest number and put it in the second position, so that you can guess that you will find n-1 numbers.

    Copy**. 1 for (int i = 0; i < 1; i++)

    Copy**. 2.Bubbling sorting: sink the maximum value of the subscript 0-n range to the n position, and the maximum value of 0-n-1 sinks to the n-1 position...

    Copy**. 1 for (int i = - 1; i > 0; i--)

    Copy**. 3.The general idea of choosing the sort is similar to the general idea of the exchange sorting, both of which refer the minimum number in a range to the first place in the range, and its generation code structure is the same as the swap row.

  6. Anonymous users2024-02-04

    The principle of selection sorting is to pick the largest (smallest) number from the number to be sorted each time and place it at the end of the ordered sequence. In practice, you only need to swap the picked number in this array with the preceding number. For example:

    Find the smallest 1, 1 and 4 exchanges.

    Find the smallest 2, 2 and 4 exchanges.

    Find the smallest 3, 3 and 5 exchanges.

    Find the smallest 4, 4 and 4 swaps (no swaps are also available).

    It can be seen that the selection sorting needs a double loop to complete, so its complexity is o(n 2) When the amount of data is relatively large, this sorting method is not recommended.

    There are many other sorting methods, and you can even design different sorting methods yourself based on different data sizes. The more common ones are bubbling sorting, insertion sorting (both of which are the same as choice sorting, both o(n 2)), dichotomous insertion sorting (reducing some complexity, but involving large-scale data movement, the efficiency is still not high), fast sorting (average complexity o(nlogn), but unstable, worst-case o(n 2)), randomized quicksort (largely avoiding the worst-case scenario), heap sorting (o(nlogn), high programming complexity), Cardinal ordering (theoretical complexity o(n), which is actually slower than this. It can even cope with string sorting, but the programming complexity is high, involving other data structures), bucket sorting (o(n), the programming is simple and efficient, but the data range can not be too large, which is limited by the memory size).

    The most commonly used thing is quick sorting, which is simple and efficient.

    Here are some of the things I know and I hope it helps you.

Related questions
7 answers2024-05-07

In the whole main function, only this one variable, whether it is the first for or the second for, is the same i, the second for will have i=-1, in the case of i= -1, and printf("%d ",a[i]);Statement. So fear not! When there is no second for the case: >>>More

12 answers2024-05-07

#include ""

#include >>>More

7 answers2024-05-07

<> the first number as the root node, divide the next number into those larger than 30 and smaller than 30, the small number is placed on the left, the large number is placed on the right, and then in the order in which the numbers appear, one by one, the larger than the root node is placed on the right, and the small one is placed on the left.

16 answers2024-05-07

Array of pointers. First of all, it is an array, the elements of the array are all pointers, and the number of bytes occupied by the array is determined by the array itself. It is short for "array of stored pointers". >>>More

10 answers2024-05-07

Here's a C implementation that assigns an array a[10] to p[n]: >>>More